[go: up one dir, main page]

bon 1.2.0

Generate builders for everything!
Documentation

crates.io Rust Documentation

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