bauer
Bauer is a crate for automatically generating Builder-patterns for your structs!
Not sure what kind of builder you want? Bauer supports a variety of sub-patterns: Owned, Borrowed, and even Type-State!
Examples
let foo: Foo = builder
.required_field
// .default_field(69) // defaults to 0
.converting_field // calls `.into()` to convert from &str -> String
.repeating_field
.repeating_field
.limited_repeating_field // If not called 1..=3 times, this will fail
.build;
Check out the repository for more examples!
Configuration
Builders are very configurable. A few of the biggest features can be found below. For a more
comprehensive collection of features, look at the Builder macro.
Kinds
Bauer supports generating 3 kinds of builders:
Owned (default) / Borrowed
"owned" builders are passed around by value and "borrowed" builders are passed by mutable
reference.
Type-State
"type-state" builders use the type-state pattern and generate builds that are validated at
compile-time using the type system.
Builder kinds can be switched between trivially using #[builder(kind = <kind>)] on the
struct.
Field Attributes
These attributes go in #[builder(..)] on individual fields of the structure
default
Specify a default value for the field to have, or use [Default::default]
repeat
Allow any structure which supports [FromIterator] to be specified by calling the function
multiple times. If repeat_n is specified, the number of times to repeat is limited.
into/tuple/adapter
Change how the generated builder function handles input. Can also be used with repeat.
intowill make the function accepetimpl Into<T>tuplewill make the function accept each item as a separate argumentadaptercan specify each argument and how they should be converted into the value
There are many more attributes, all can be found on the Builder macro.