Expand description
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 example
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.
§License
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.
Macros§
- Creates a fixed-size array literal where each element is converted with
Into::into()
into the target type. - Same as
std::vec!
but converts each element withInto::into()
.
Attribute Macros§
- Can be placed on top of a free function or an associated method or a struct declaration. Generates a builder for the item beneath it.