This crate is based around two traits, [Buildable
] and
[Generatable
], and their associated derive macros, which provide
ways to construct objects succinctly.
Builder
A [Builder
] is a way to create a single object, specifying only the
fields you wish to give non-default values. The default values are
specified using attributes on your type for ease of reading. Each
field gains a method of the same type in the builder which can be
be used to customise it.
Example
use ;
let f = builder
.a
.build;
assert_eq!;
assert_eq!;
Generator
A [Generator
] is a way to create an infinite sequence of
objects, again specifying only the functions for generating the
fields you wish to have non-default sequences. The default
sequences are specified using attributes on your type for ease of
reading. Each field gains a method of the same name in the
generator, which can be be used to customise the sequence of
values produced for that field as objects are made.
Example
use ;
let mut n = 2;
let mut gen = generator
.a;
let bar1 = gen.generate;
assert_eq!;
assert_eq!;
let bar2 = gen.generate;
assert_eq!;
assert_eq!;