Default
FieldX can provide implicit implementation of the Default trait for a struct in one of the following cases:
-
When the argument
<a name="a001"></a>defaultis provided and active to thefxstructmacro.#[fxstruct(default)] struct Foo { is_set: bool, } -
When the argument
defaultis provided and active for any field'sfieldxattribute.#[fxstruct] struct Foo { #[fieldx(get(copy), default(3.1415926535))] pi: f32, } let foo = Foo::default(); assert_eq!(foo.pi(), 3.1415926535); -
When another argument, like the struct level
newargument, needs it.#[fxstruct(new)] struct Bar { #[fieldx(get(copy), default(2.7182818284))] e: f32, } let bar = Bar::new(); assert_eq!(bar.e(), 2.7182818284);