[−][src]Macro factori::create
A macro to instantiate an instance of a factory.
The type must already have had a factory defined using the factori!()
macro.
The create!()
macro accepts:
-
The type to be instantiated using its factory.
-
Zero or more comma-separated mixins using the syntax
:name
.These are applied in the order that they are passed to
create!()
, which means that later mixins might override attributes already set by earlier mixins.You can think of the default values defined in the factory's
default
block as an implicit mixin which is always included first in every call tocreate!()
. -
Zero or more named fields with values,
field: value
.These override both the factory's default values and the provided mixins. Each field from the
default
block can appear zero or one times.
Example
struct Vehicle { registration: &'static str, number_wheels: u8, number_seats: u8, } factori!(Vehicle, { default { registration = "", number_wheels = 4, number_seats = 5, } mixin motorbike { number_wheels = 2, number_seats = 1, } mixin trike { number_wheels = 3 } }); fn main () { let trike = create!(Vehicle, :motorbike, :trike, registration: "J105 SRA"); assert_eq!(trike.number_wheels, 3); assert_eq!(trike.number_seats, 1); }