Default Macro

A convenient macro to implement Default for structs using field initializers.
Example
Add this to your Cargo.toml:
[dependencies]
default2 = "2"
Use the default2::default! macro to define a struct and its default values in one place.
default2::default! {
#[derive(Debug, PartialEq)]
struct Process {
id: i32 = 10,
name: String = "main".into(),
cpus: usize = num_cpus::get(),
payload: u64,
}
}
The macro will generate the standard struct definition along with a Default implementation:
#[derive(Debug, PartialEq)]
struct Process {
id: i32,
name: String,
cpus: usize,
payload: u64,
}
impl Default for Process {
fn default() -> Self {
Process {
id: 10,
name: "main".into(),
cpus: num_cpus::get(),
payload: std::default::Default::default(),
}
}
}