Another builder macro-based generator with its own idioms.
"Maçon" is French translation for "builder"
Usage
extern crate macon;
let _mytype: MyType = builder
.integer
.string
.build;
- adds a builder struct (
<TargetStruct>Builder) - build struct implements
Default - adds a
builder()function to target struct to initialize a new builder - each target struct field can be set with function of same name and parameter of same type
- use
build()function to create new target struct instance - any unset field will make
build()call not compile (default)
Features
Typestate pattern (default)
By default, builder rely on typestate pattern. It means state is encoded in type (using generics). Applicable functions are implemented (callable) only when state (type) matches:
- Build function
build()when all properties has been set - Each property setter function as long as property haven't been set
Optionally, you can set it explictly:
extern crate macon;
Panic on build()
By default, builder rely on typestate pattern to avoid misconfiguration by adding compilation constraint. You can switch to a builder that just panic when misconfigured:
let _mytype: MyType = builder
.integer
.build;
Result on build()
By default, builder rely on typestate pattern to avoid misconfiguration by adding compilation constraint. You can switch to a builder
that returns a Result:
extern crate macon;
let myTypeResult: = builder
.integer
.build;
assert!;