Crate simple_builder
source ·Expand description
Simple-builder is a simple-as-possible implementation of the builder pattern for arbitrary Rust structs. It seeks to provide an easy to use interface for common use cases, such as web request with many optional parameters.
Implementation
The derived builders offer compile-time guarantees that no incorrect instance will be created
without super-linear compile times since required parameters go directly in the new
method of
the builder.
There are two downsides to this:
- The derived builders have lengthy constructors for structs with many required parameters. This is arguably no longer a builder pattern, and as such isn’t suitable for structs with many required parameters.
- Calling
build
twice will result in a panic, since it owns and consumes the passed in data.
Other implementations may suit your needs better if you have many required parameters, need to clone your builders, or have strict requirements for compile-time type checking of required parameters and intermediate states.
Derive Macros
- Macro that derives a Builder object for any given struct. E.g.
SomeType
->SomeTypeBuilder
.