derive_builder
A Rust derive macro that generates the builder pattern for arbitrary structs
Repository Health
Technical Analysis
derive_builder is a Rust procedural macro that automatically implements the builder pattern for your structs. Adding a single #[derive(Builder)] attribute to a struct Foo generates a FooBuilder type with fluent setter methods for every field and a build method that assembles the final value, eliminating the boilerplate you would otherwise write by hand.
The macro is highly configurable through builder attributes: you can convert setter inputs with Into, mark fields optional or defaulted, add validation in a custom build function, rename methods, and control mutability. It is one of the most widely used code-generation crates in the Rust ecosystem.
What You Get
- A generated <Name>Builder type with fluent, chainable setter methods
- A build() method that validates required fields and returns your struct or an error
- Attribute options for Into conversions, defaults, optional fields, and renaming
- Support for custom validation via a user-provided build function
- no_std and no_alloc compatibility for constrained environments
Common Use Cases
- Constructing structs that have many optional or defaulted configuration fields
- Providing a clean public constructor API for library configuration types
- Building complex request or options objects with readable, chained calls
- Avoiding hand-written builder boilerplate across large codebases
Under The Hood
Architecture - The project is a Cargo workspace split into derive_builder (the public crate re-exporting the macro and runtime pieces), derive_builder_macro (the thin proc-macro entry point), and derive_builder_core (the code-generation logic that parses #[builder(...)] attributes and emits the builder struct, setters, and build fn). Dedicated no_std and no_alloc test crates verify constrained targets.
Tech Stack - Rust (MSRV 1.56) built on the syn/quote/proc-macro2 stack for parsing and token generation. Managed with Cargo; a dev/ directory holds development tooling.
Code Quality - A mature, heavily depended-upon crate (over 165M downloads) with a maintained CHANGELOG, extensive compile-and-run tests including UI tests for macro diagnostics, and separate test crates for no_std/no_alloc guarantees. Recent development activity is modest but the API is stable.
API Design - The core experience is a single #[derive(Builder)], with a rich but discoverable attribute vocabulary (setter(into), default, build_fn, field-level overrides) that scales from trivial cases to complex validation without leaving the derive.
Used by 2 apps in this directory
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.
Rivet
AI Agents · Developer Tools
Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.