macro_rules! impl_display_with_writeable {
(@display, $type:ty $(, where $($generics:tt)*)?) => { ... };
($type:ty $(, #[$alloc_feature:meta])? $(, where $($generics:tt)*)?) => { ... };
}Expand description
Implements Display for types that implement Writeable.
It’s recommended to do this for every Writeable type, as it will add
support for core::fmt features like fmt!,
print!, write!, etc.
This macro also adds a concrete to_string function. This function will shadow the
standard library ToString, using the more efficient writeable-based code path.
To add only Display, use the @display macro variant.
If your type has generics, list them in a where clause in the macro invocation.
§Examples
use writeable::Writeable;
use std::fmt;
struct Message<T>(T);
impl<T> Writeable for Message<T> where T: Writeable {
fn write_to<W: fmt::Write + ?Sized>(&self, sink: &mut W) -> fmt::Result {
sink.write_str("Message: ")?;
self.0.write_to(sink)
}
// ...
}
writeable::impl_display_with_writeable!(Message<T>, where T: Writeable);
writeable::assert_writeable_eq!(Message("hello"), "Message: hello");