Macro impl_more::forward_deref_and_mut

source ·
macro_rules! forward_deref_and_mut {
    ($ty:ty => $target:ty) => { ... };
    ($ty:ty => ref $target:ty) => { ... };
    ($ty:ty => $field:ident : $target:ty) => { ... };
    ($ty:ty => $field:ident : ref $target:ty) => { ... };
}
Expand description

Implements Deref and DerefMut by forwarding through an inner field’s implementation.

Use the ref <type> form for deref-ing to types with lifetimes like &str. For newtype structs, only the struct name and deref target type is necessary.

Also see impl_deref_and_mut.

§Examples

With a newtype struct:

struct MyNewTypeStruct(String);
impl_more::forward_deref_and_mut!(MyNewTypeStruct => ref str);
let mut foo = MyNewTypeStruct("one".to_owned());
let foo_ref: &str = &foo;
accepts_string_slice(&foo);
accepts_mut_string_slice(&mut foo);