bon
is a Rust crate for generating compile-time-checked builders for functions and structs.
Visit the guide for a complete overview of the crate.
Quick examples
bon
can turn a function with positional parameters into a function with "named" parameters via a builder. It's as easy as placing the #[builder]
attribute on top of it.
use builder;
let greeting = greet
.name
.age
.call;
assert_eq!;
You can also use the #[builder]
attribute with structs and associated methods:
use ;
let user = builder
.id
.name
.build;
let greeting = user
.greet
.target
// `level` is optional, we can omit it here
.call;
assert_eq!;
assert_eq!;
assert_eq!;
See the guide for the rest.
If you like the idea of this crate and want to say "thank you" or "keep doing this" consider giving us a star ⭐ on Github. Any support and contribution are appreciated 🐱!