Crates.io | custom_default |
lib.rs | custom_default |
version | 0.0.2 |
source | src |
created_at | 2019-01-27 01:51:52.437475 |
updated_at | 2019-01-28 18:32:13.222087 |
description | generate custom default values for struct fields |
homepage | |
repository | https://github.com/slmjkdbtl/custom_default/ |
max_upload_size | |
id | 110850 |
size | 5,056 |
generate custom default values for struct fields
use custom_default::CustomDefault;
#[derive(CustomDefault, Debug)]
struct Person {
#[default("Jack")]
name: &'static str,
#[default(12)]
age: u32,
#[default(true)]
dead: bool,
// without the `default` attr it will work like normal `#[derive(Default)]`
size: usize,
}
assert!(Person::default() == Person {
name: "Jack",
age: 12,
dead: true,
size: 0,
});