Crates.io | default2 |
lib.rs | default2 |
version | |
source | src |
created_at | 2023-05-31 02:18:54.421861+00 |
updated_at | 2025-02-20 18:34:26.255604+00 |
description | Default implementation using macros |
homepage | https://github.com/yaa110/default2 |
repository | https://github.com/yaa110/default2 |
max_upload_size | |
id | 878471 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Default implementation using macros
Use default2::Default
to set default value of each field using a macro:
#[derive(default2::Default)]
struct Process {
#[default(10)]
id: i32,
#[default("main".into())]
name: String,
#[default(num_cpus::get())]
cpus: usize,
#[default(vec![1, 2, 3])]
vector: Vec<u64>,
payload: u64,
}
The following code will be generated:
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(),
vector: vec![1, 2, 3],
payload: Default::default(),
}
}
}