1macro_rules! impl_str_basic {
2 ($type:ty) => {
3 impl zvariant::Basic for $type {
4 const SIGNATURE_CHAR: char = <zvariant::Str<'_>>::SIGNATURE_CHAR;
5 const SIGNATURE_STR: &'static str = <zvariant::Str<'_>>::SIGNATURE_STR;
6 }
7 };
8}
9
10macro_rules! impl_try_from {
11 (ty: $type:ty, owned_ty: $owned_type:ty, validate_fn: $validate_fn:ident, try_from: [$($from:ty),*],) => {
12 $(
13 impl<'s> TryFrom<$from> for $type {
14 type Error = Error;
15
16 fn try_from(value: $from) -> Result<Self> {
17 let value = Str::from(value);
18 $validate_fn(value.as_str())?;
19 Ok(Self(value))
20 }
21 }
22
23 impl<'s> TryFrom<$from> for $owned_type {
24 type Error = Error;
25
26 fn try_from(value: $from) -> Result<Self> {
27 Ok(Self::from(<$type>::try_from(value)?))
28 }
29 }
30 )*
31 };
32}
33
34pub(crate) use impl_str_basic;
35pub(crate) use impl_try_from;