#default #default-value #struct-fields #generate

yanked custom_default

generate custom default values for struct fields

0.0.2 Jan 28, 2019
0.0.1 Jan 27, 2019
0.0.0 Jan 27, 2019

#57 in #default-value

Zlib license

4KB
64 lines

custom_default

generate custom default values for struct fields

example

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,
});

Dependencies

~2MB
~47K SLoC