Skip to main content

forward_as_ref_and_mut

Macro forward_as_ref_and_mut 

Source
macro_rules! forward_as_ref_and_mut {
    (<$($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 AsRef and AsMut by forwarding to a field’s implementations.

This macro has the same type parameter support and format as forward_as_ref.

§Examples

use impl_more::forward_as_ref_and_mut;

struct Foo(String);
forward_as_ref_and_mut!(Foo => str);

let mut foo = Foo("bar".to_owned());
foo.as_mut().make_ascii_uppercase();

assert_eq!(foo.as_ref(), "BAR");