derive-debug
This crate implements a more customizable version of #[derive(Debug)].
This is a fork of derive-debug
The difference
- alias allow expr
- expr option
- sort
- flat option
Usage
The usage is very similar to #[derive(Debug)] with a few extra customization options.
Deriving a struct
use Dbg;
Deriving an enum
use Dbg;
Detailed options
Field Options
#[dbg(skip)]completely omits a field in the output
use Dbg;
// Outputs: Foo { field_a: true }
#[dbg(placeholder = "xyz")]will printxyzinstead of the actual contents of a field
use Dbg;
// Outputs: Foo { field_a: true, field_b: ... }
#[dbg(alias = "some_alias")]will printsome_aliasas field name instead of the real name
use Dbg;
// Outputs: Foo { field_a: true, not_field_b: 42, expr_b: 137 }
#[dbg(fmt = "{:#06X}")]will print the field with the specified format
use Dbg;
// Outputs: Foo { field_a: true, field_b: 0x002A }
#[dbg(formatter = "my_func")]will print the field using the specified function.
The function has to return a type that can be formatted using "{}"
use Dbg;
] u32);
// Outputs: Foo(42, not 0)
#[dbg(expr = &"123")]will pass the expression directly into
use Dbg;
// Outputs: Foo { field_a: true, field_b: "123" }
#[dbg(sort = -1)]
use Dbg;
// Outputs: Foo { field_b: 123, field_a: true }
#[dbg(flat_option)]
use Dbg;
// Outputs: Foo { field_b: 123 }
Enum Variant Options
#[dbg(skip)]only prints the name of the variant and omits its contents
use Dbg;
// Outputs: SomeVariant
#[dbg(alias = "some_alias")]will usesome_aliasas variant name instead of the real name
use Dbg;
// Outputs: NotSomeVariant { a: true, b: 42 }
struct Options
#[dbg(alias = "MyAlias")]will useMyAliasas struct name instead of the real name
use Dbg;
// Outputs: NotFoo { field_a: true, not_field_b: 42 }