Crate const_typed_builder
source ·Expand description
Builder Derive Macro Documentation
The Builder derive macro is used to generate builder methods for structs in Rust. These builder methods allow you to construct instances of the struct by chaining method calls, providing a convenient and readable way to create complex objects with various configurations and compile-time validity checking. This documentation will provide an overview of how to use the Builder derive macro.
Prerequisites
To use the Builder derive macro, you should have the const_typed_builder crate added to your project’s dependencies in your Cargo.toml file:
[dependencies]
const_typed_builder = "0.1"
Also, make sure you have the following import statements in your code:
use const_typed_builder::Builder;Inspirations
Builder macros have been done before, but not exactly what I needed for my use case. Also look into derive_builder and typed-builder. Those projects are currently way more mature, but anyone willing to test this crate is currently a godsend.
Traits
- The
Buildertrait facilitates the creation of builder patterns for Rust struct types. It provides a common interface for generating builders that enable the construction of instances of a struct with various configurations and compile-time validity checking.
Derive Macros
- The
Builderderive macro provides a convenient and ergonomic way to create builder patterns for struct types in Rust. It allows you to generate builder methods for constructing instances of a struct with various features and constraints, all checked at compile time. Below are the highlighted features and explanations for each, along with examples: