macro_rules! derive_serialize_from_display { ($type:ident $(:: $type_extra:ident)* < $($lt:lifetime),+ >) => { ... }; ($type:ty) => { ... }; }
Expand description
Derives Serialize a type that implements Display.
use std::fmt;
use serde_plain::derive_serialize_from_display;
pub struct MyStruct(u32);
impl fmt::Display for MyStruct {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
derive_serialize_from_display!(MyStruct);This automatically implements Serialize which will
invoke the to_string method on the target.