Skip to content

Deaths-Door/bon

 
 

Repository files navigation

bon logo

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

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.

About

Generate builders for everything!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 83.9%
  • Shell 8.9%
  • TypeScript 5.6%
  • Vue 1.5%
  • CSS 0.1%