Chapter 1: Getting Started with bon
- Recipe 1: Adding bon to Your Project
- Recipe 2: Your First
#[builder]on a Free Function - Recipe 3: Your First
#[derive(Builder)]on a Struct - Recipe 4: Using
#[bon]and#[builder]onimplBlocks - Recipe 5: Understanding Naming Conventions
Chapter 2: Required and Optional Members
- Recipe 6: Marking a Field as Required
- Recipe 7: Using
Optionfor Optional Members - Recipe 8: Using
#[builder(default)]with theDefaultTrait - Recipe 9: Using
#[builder(default = expr)]with a Custom Expression - Recipe 10: Referencing Other Members in
defaultExpressions - Recipe 11: Switching Between
Optionand#[builder(default)]Without Breaking Callers
Chapter 3: The Typestate Pattern Under the Hood
- Recipe 12: Understanding How bon Uses Typestate to Enforce Required Fields
- Recipe 13: Reading Compile Errors for Missing Required Members
- Recipe 14: Reading Compile Errors for Duplicate Setter Calls
- Recipe 15: Exposing the Typestate API for Custom Builder Methods
- Recipe 16: Adding Custom Setter Methods via
implon the Builder
Chapter 4: Setter Customization
- Recipe 17: Renaming a Setter with
#[builder(name = ...)] - Recipe 18: Enabling
IntoConversions with#[builder(into)] - Recipe 19: Applying
Intoto Multiple Fields with#[builder(on(...))] - Recipe 20: Custom Setter Logic with
#[builder(with = |...| ...)] - Recipe 21: Skipping a Member with
#[builder(skip)] - Recipe 22: Overwritable Setters
Chapter 5: Working with Functions and Methods
- Recipe 23:
#[builder]on Async Functions - Recipe 24:
#[builder]on Fallible Functions ReturningResult - Recipe 25:
#[builder]on Generic Functions - Recipe 26:
#[builder]on Functions withimpl TraitParameters - Recipe 27:
#[builder]on Methods with&selfand&mut self - Recipe 28:
#[builder]on Associated Functions Not Namednew - Recipe 29: Handling Destructuring Patterns
Chapter 6: Visibility and Documentation
- Recipe 30: Controlling Visibility of the Generated Builder Struct
- Recipe 31: Controlling Visibility of Individual Setters
- Recipe 32: Adding Doc Comments to the Builder and Its Methods
- Recipe 33: Documenting Optional vs Required Fields in Generated Docs
- Recipe 34: Hiding Builder Internals from Public API with Visibility Tricks
Chapter 7: Validation and Finishing Functions
- Recipe 35: Validating Inputs Inside the Constructor Function Body
- Recipe 36: Renaming
build()with#[builder(finish_fn = ...)] - Recipe 37: Making the Finish Function Fallible
- Recipe 38: Customizing the Start Function Name with
start_fn - Recipe 39: Building a Validated Domain Type with a Private Struct and Builder Function
Chapter 8: Getters and Derives on the Builder
- Recipe 40: Generating Getters for Builder Fields with
#[builder(getter)] - Recipe 41: Configuring Getter Visibility and Naming
- Recipe 42: Deriving Traits on the Builder with
#[builder(derive(...))] - Recipe 43: Generating
impl From for Twith#[builder(derive(Into))]
Chapter 9: Patterns for Real-World APIs
- Recipe 44: Builder for a Configuration Struct
- Recipe 45: Builder for a Query or Request Object
- Recipe 46: Conditional Building Based on Optional Fields
- Recipe 47: Composing Builders
- Recipe 48: Builder with
serde::Deserializeon the Same Struct - Recipe 49: Builder with
CloneandDebugDerives
Chapter 10: Shared Configuration and Reuse
- Recipe 50: Applying the Same
#[builder(...)]Config to Many Structs withmacro_rules_attribute - Recipe 51: Wrapping bon Macros in Your Own Proc Macro
- Recipe 52: Controlling the Builder Type Name
Chapter 11: Testing and Ergonomics
- Recipe 53: Testing Builders in Unit Tests
- Recipe 54: Using
experimental-overwritableto Reduce Boilerplate in Test Fixtures - Recipe 55: Snapshot Testing Builder Outputs with
insta - Recipe 56: IDE Autocomplete and Rust Analyzer Integration
Chapter 12: bon vs. The Alternatives
- Recipe 57: bon vs.
derive_builder - Recipe 58: bon vs.
typed-builder - Recipe 59: Migrating from
derive_builderto bon - Recipe 60: Migrating from
typed-builderto bon - Recipe 61: When Not to Use a Builder