1macro_rules! impl_try_from {
2 (ty: $type:ty, owned_ty: $owned_type:ty, validate_fn: $validate_fn:ident, try_from: [$($from:ty),*],) => {
3 $(
4 impl<'s> TryFrom<$from> for $type {
5 type Error = Error;
6
7 fn try_from(value: $from) -> Result<Self> {
8 let value = Str::from(value);
9 $validate_fn(value.as_str())?;
10 Ok(Self(value))
11 }
12 }
13
14 impl<'s> TryFrom<$from> for $owned_type {
15 type Error = Error;
16
17 fn try_from(value: $from) -> Result<Self> {
18 Ok(Self::from(<$type>::try_from(value)?))
19 }
20 }
21 )*
22 };
23}
24
25pub(crate) use impl_try_from;
26