Skip to content

Commit

Permalink
Merge pull request #347 from linebender/try-from-string-name
Browse files Browse the repository at this point in the history
Implement `TryFrom<String>` for `Name`
  • Loading branch information
RickyDaMa authored May 23, 2024
2 parents e8ea936 + 98965f0 commit bc069f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ impl FromStr for Name {
}
}

impl TryFrom<String> for Name {
type Error = NamingError;

fn try_from(value: String) -> Result<Self, Self::Error> {
if is_valid(&value) {
Ok(Name(value.into()))
} else {
Err(NamingError::Invalid(value))
}
}
}

impl<'de> Deserialize<'de> for Name {
fn deserialize<D>(deserializer: D) -> Result<Name, D::Error>
where
Expand Down
4 changes: 2 additions & 2 deletions src/serde_xml_plist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mod de {

pub(super) struct DictWrapper(pub(super) Dictionary);

struct ValueWrapper(Value);
struct ValueWrapper;

struct ArrayWrapper(Vec<Value>);

Expand Down Expand Up @@ -135,7 +135,7 @@ mod de {
where
D: Deserializer<'de>,
{
deserializer.deserialize_any(ValueVisitor).map(ValueWrapper)
deserializer.deserialize_any(ValueVisitor).map(|_| ValueWrapper)
}
}

Expand Down

0 comments on commit bc069f4

Please sign in to comment.