A Rust crate for generating compile-time-checked builders for structs and functions with named parameters and optional arguments.
Bon is a Rust crate that generates compile-time-checked builders for structs and functions, enabling named parameters and optional arguments. It solves the problem of constructing complex objects or function calls with many parameters by providing a safe, flexible, and ergonomic builder API that prevents runtime errors through compile-time validation.
Rust developers building libraries or applications that require flexible object construction, such as configuration builders, API clients, or data models with many optional fields.
Developers choose Bon for its compile-time safety guarantees, seamless integration with Rust's type system, and support for advanced features like async functions and `no_std` environments, making it a more robust alternative to other builder crates.
Next-gen compile-time-checked builder generator, named function's arguments, and more!
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses the typestate pattern to enforce required parameters and prevent duplicate setters, eliminating runtime panics as emphasized in the README.
Converts positional function parameters into named arguments with the #[builder] attribute, improving readability and enabling partial application, as shown in the greet function example.
Works seamlessly with async, fallible, generic functions, and impl Trait, making it versatile for complex Rust code, as noted in the overview.
Ensures all errors are caught at compile time, preventing runtime failures, which is a core philosophy highlighted in the README.
Provides a comprehensive guide book and API reference with detailed examples, as linked in the README for easy navigation.
Requires both #[bon] on the impl block and #[builder] on methods, adding boilerplate compared to simple struct builders, as seen in the method builder examples.
Heavy reliance on procedural macros can increase compile times and may cause issues with IDE tooling, a common trade-off for compile-time safety.
As a newer crate, it has fewer community resources and integrations compared to established alternatives like derive_builder, which the README acknowledges as inspiration.