Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Rust
  3. bon

bon

Apache-2.0Rustv3.10.2

A Rust crate for generating compile-time-checked builders for structs and functions with named parameters and optional arguments.

Visit WebsiteGitHubGitHub
2.1k stars47 forks0 contributors

What is bon?

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.

Target Audience

Rust developers building libraries or applications that require flexible object construction, such as configuration builders, API clients, or data models with many optional fields.

Value Proposition

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.

Overview

Next-gen compile-time-checked builder generator, named function's arguments, and more!

Use Cases

Best For

  • Generating type-safe builders for configuration structs with many optional fields
  • Adding named arguments to functions for improved readability and partial application
  • Creating ergonomic APIs for library consumers with compile-time error checking
  • Building complex objects in `no_std` environments with optional cargo features
  • Implementing method builders for associated functions in Rust structs
  • Ensuring builder usage is free from runtime panics via the typestate pattern

Not Ideal For

  • Projects with simple structs that can be initialized directly without many optional fields
  • Teams that require dynamic, runtime configuration changes in builder parameters
  • Codebases already using established builder crates like typed-builder or derive_builder
  • Environments where minimizing procedural macro usage is critical for fast compile times

Pros & Cons

Pros

Compile-Time Safety

Uses the typestate pattern to enforce required parameters and prevent duplicate setters, eliminating runtime panics as emphasized in the README.

Named Arguments Support

Converts positional function parameters into named arguments with the #[builder] attribute, improving readability and enabling partial application, as shown in the greet function example.

Advanced Feature Compatibility

Works seamlessly with async, fallible, generic functions, and impl Trait, making it versatile for complex Rust code, as noted in the overview.

No Panics Guarantee

Ensures all errors are caught at compile time, preventing runtime failures, which is a core philosophy highlighted in the README.

Good Documentation

Provides a comprehensive guide book and API reference with detailed examples, as linked in the README for easy navigation.

Cons

Complex Setup for Methods

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.

Macro Overhead

Heavy reliance on procedural macros can increase compile times and may cause issues with IDE tooling, a common trade-off for compile-time safety.

Limited Ecosystem

As a newer crate, it has fewer community resources and integrations compared to established alternatives like derive_builder, which the README acknowledges as inspiration.

Frequently Asked Questions

Quick Stats

Stars2,139
Forks47
Contributors0
Open Issues28
Last commit2 days ago
CreatedSince 2024

Tags

#macro#macros#constructor#data-structures#asynchronous#builder-pattern#named-arguments#derive-macro#compile-time-checking#rust#no-std#code-generation#builder

Built With

R
Rust

Links & Resources

Website

Included in

Rust56.6k
Auto-fetched 1 day ago

Related Projects

cutecute

Macro for Python-esque comprehensions in Rust

Stars345
Forks8
Last commit7 years ago
Linq-in-RustLinq-in-Rust

Language Integrated Query in Rust.

Stars142
Forks8
Last commit2 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub