impl_more

Macro forward_display

source
macro_rules! forward_display {
    (<$($generic:ident),+> in $this:ty => $field:ident) => { ... };
    (<$($generic:ident),+> in $this:ty) => { ... };
    ($ty:ty) => { ... };
    ($ty:ty => $field:ident) => { ... };
}
Expand description

Implements Display for structs by forwarding to one of its field.

Emitted code is not compatible with #[no_std].

Newtype structs can omit the field identifier.

ยงExamples

For newtype struct:

struct Foo(String);

impl_more::forward_display!(Foo);

assert_eq!(Foo("hello world".to_owned()).to_string(), "hello world");

For struct with named field:

struct Bar {
    inner: u64,
}

impl_more::forward_display!(Bar => inner);

assert_eq!(Bar { inner: 42 }.to_string(), "42");

For generic newtype struct (note that Display bounds are applied to all type parameters):

struct Baz<T>(T);

impl_more::forward_display!(<T> in Baz<T>);

assert_eq!(Baz(42u64).to_string(), "42");