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.
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]
macro on top of it.
use bon::builder;
#[builder]
fn greet(name: &str, age: u32) -> String {
format!("Hello {name} with age {age}!")
}
let greeting = greet()
.name("Bon")
.age(24)
.call();
assert_eq!(greeting, "Hello Bon with age 24!");
See the guide for the rest.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.