macro_rules! wrapper {
($vis:vis $name:ident$(<$($lt:tt$(:$clt:tt$(+$dlt:tt)*)?),+>)? ($inner_vis:vis $inner:ty) $(, <$($plt_name:ident: $plt:lifetime),+>)? $(, derive($($derive:path),+))?) => { ... };
}
Expand description
Helper macro for creating a wrapper type.
The wrapper type will implement Deref
,
DerefMut
, From
and AsRef
.
ยงExample
wrapper!(pub MyString(String));
// Derive is OK!
wrapper!(pub MyStringDerived(String), derive(Debug, Clone, PartialEq, Eq, Hash));
// Lifetime is supported too!
wrapper!(pub MyStringLifetime<'a>(&'a str));
wrapper!(pub MyStringLifetimePubDerived<'a>(pub &'a str), derive(Debug, Clone, PartialEq, Eq, Hash));
Reference: https://stackoverflow.com/a/61189128