Lets you derive Display
and Debug
traits by delegating them to the only member of 0..1
-member structs & enums.

use delegate_display::{DelegateDebug, DelegateDisplay};
use std::fmt;
#[derive(DelegateDebug, DelegateDisplay)]
enum MyEnum {
Foo,
Bar(SomeType),
Qux { baz: SomeType },
}
impl fmt::Display for MyEnum {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Foo => f.write_str("Foo"),
Self::Bar(value) => fmt::Display::fmt(value, f),
Self::Qux { baz } => fmt::Display::fmt(baz, f),
}
}
}
See module-level documentation for more examples, what's allowed and what isn't.