Macro impl_more::impl_deref
source · [−]macro_rules! impl_deref {
(<$($generic:ident),+> in $this:ty => $target:ty) => { ... };
(<$($generic:ident),+> in $this:ty => $field:ident : $target:ty) => { ... };
($this:ty => $target:ty) => { ... };
($this:ty => $field:ident : $target:ty) => { ... };
}Expand description
Implement Deref for a struct.
The first argument is that of the newtype struct to create the impl for and the second is the deref target type. The third argument is required for non-newtype structs and is the name of the field to deref to. Type parameters require special handling, see examples.
Also see impl_deref_mut, impl_deref_and_mut, and forward_deref_and_mut.
Examples
use impl_more::impl_deref;
struct Foo(String);
impl_deref!(Foo => String);
let mut foo = Foo("bar".to_owned());
assert_eq!(foo.len(), 3);use impl_more::impl_deref;
struct Foo { msg: String }
impl_deref!(Foo => msg: String);
let mut foo = Foo { msg: "bar".to_owned() };
assert_eq!(foo.len(), 3);