Lets you derive Display
& Debug
traits on structs with
0..=1
fields & enums where each variant has 0..=1
fields - see input/output examples below.
```rust // Input
struct Foo(SomeType);
// Output impl fmt::Display for Foo { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&self.0, f) } } ````
```rust // Input
struct Foo { some_field: SomeType }
// Output impl fmt::Debug for Foo { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'>) -> fmt::Result { fmt::Debug::fmt(&self.somefield, f) } } ````
```rust // Input enum MyEnum { Foo, Bar(SomeType), Qux { baz: SomeType } }
// Output fn fmt(&self, f: &mut fmt::Formatter<'>) -> fmt::Result { match self { Self::Foo => f.writestr("Foo"), Self::Bar(inner) => DebugOrDisplay::fmt(inner, f), Self::Qux { baz } => DebugOrDisplay::fmt(baz, f), } } ````
```rust // Input struct Foo; struct Bar{} struct Qux(); enum Baz {}
// Output fn fmt(&self, : &mut fmt::Formatter<'>) -> fmt::Result { Ok(()) } ````
The attribute names are ddebug
for Debug
, ddisplay
for Display
and dboth
for a common config for
both. ddebug
and ddisplay
take precendence over dboth
.
base_bounds
will add whatever trait is being derived as a generic bound to each of the struct/enum's generic paramsbounds(...)
will let you specify specific bounds```rust // Input
enum Foo
// Output
impl
```rust
struct TooManyFields1 { foo: u8, bar: u8, // Only one field permitted } ```
```rust
struct TooManyFields2(u8, u8); // too many fields ```
```rust
enum SomeEnum { A, // this is ok B(u8), // this is ok C { foo: u8 }, // this is ok D(u8, u8), // Only one field permitted E { foo: u8, bar: u8 } // Only one field permitted } ```