Default Macro
A convenient macro to implement Default for structs using field initializers.
Usage
Add this to your Cargo.toml:
[]
= "2"
Example
Use the default2::default! macro to define a struct and its default values in one place.
default!
The macro will generate the standard struct definition along with a Default implementation:
Const Defaults
You can also generate a const default function by adding the #[const_default] attribute to your struct. This will generate an inherent method const_default().
You are responsible for ensuring that all default value expressions are valid in a const context.
use default;
default!
// You can now create a const instance:
const MY_CONFIG: MyConfig = const_default;
assert_eq!;
// The standard non-const Default trait is still implemented:
let other_config = default;
assert_eq!;