diff --git a/src/name.rs b/src/name.rs index 8a114766..688d4d8e 100644 --- a/src/name.rs +++ b/src/name.rs @@ -101,6 +101,18 @@ impl FromStr for Name { } } +impl TryFrom for Name { + type Error = NamingError; + + fn try_from(value: String) -> Result { + if is_valid(&value) { + Ok(Name(value.into())) + } else { + Err(NamingError::Invalid(value)) + } + } +} + impl<'de> Deserialize<'de> for Name { fn deserialize(deserializer: D) -> Result where