This is a drop-in replacement for #[derive(Debug)]
that uses serde::Serialize
under the hood to provide advanced control over output serialisation.
By default, the generated code will produce exactly same output as #[derive(Debug)]
for compatibility.
However, this might be not very interesting, so let's add some Serde attributes to see how we can control debug representation:
```rust extern crate serde;
extern crate serde_derive;
extern crate serdebug;
pub struct CustomType(u32);
pub enum MyEnum { // renaming items works as expected #[serde(rename = "AAAAAAA!!!")] A,
B(u32),
C { flag: bool },
}
// so does bulk rename on containers
pub struct MyStruct { number: u32,
my_enum: Vec<MyEnum>,
// we might want to hide some items from the output
#[serde(skip_serializing)]
hidden: bool,
// or override serialisation for otherwise verbose wrappers or
// third-party types that don't implement `Debug` and/or `Serialize`
#[serde(serialize_with = "custom_serialize")]
custom_type: CustomType,
}
fn custom_serialize
value.0.serialize(ser)
}
fn main() { let s = MyStruct { number: 42, myenum: vec![MyEnum::A, MyEnum::B(10), MyEnum::C { flag: true }], hidden: true, customtype: CustomType(20), };
assert_eq!(format!("{:#?}", s), "
MyStruct { Number: 42, MyEnum: [ AAAAAAA!!!, B( 10 ), C { flag: true } ], CustomType: 20 } ".trim()); } ```