Skip to main content

impl_writeable_delegate

Macro impl_writeable_delegate 

Source
macro_rules! impl_writeable_delegate {
    ($ty:ty, |&$self:ident| $delegate:expr $(, #[$alloc_feature:meta] fn write_to_string)? $(, where $($generics:tt)*)?) => { ... };
}
Expand description

Macro to implement Writeable by delegating to another Writeable.

Useful for wrapper types.

ยงExamples

struct MyStruct(String);
writeable::impl_writeable_delegate!(MyStruct, |&self| &self.0);
writeable::impl_display_with_writeable!(MyStruct);

writeable::assert_writeable_eq!(MyStruct("hello".to_string()), "hello");

With a cfg on fn write_to_string:

struct MyStruct(String);
writeable::impl_writeable_delegate!(MyStruct, |&self| &self.0, #[cfg(feature = "alloc")] fn write_to_string);
writeable::impl_display_with_writeable!(MyStruct, #[cfg(feature = "alloc")]);

writeable::assert_writeable_eq!(
    MyStruct("hello".to_string()),
    "hello"
);

With generics:

use writeable::Writeable;

struct MyStruct<T>(T);
writeable::impl_writeable_delegate!(MyStruct<T>, |&self| &self.0, where T: Writeable);
writeable::impl_display_with_writeable!(MyStruct<T>, where T: Writeable);

writeable::assert_writeable_eq!(
    MyStruct("hello"),
    "hello"
);