1 unstable release

0.2.0 Aug 20, 2024

#2133 in Procedural macros

Download history 135/week @ 2024-08-19 9/week @ 2024-08-26

144 downloads per month
Used in buco

Custom license

12KB
248 lines

buco (Builder at Compile Time)

A simple crate for implementing builder pattern, while still maintaining the safety and predictability of the Rust compiler.

Usage

Add the following to your Cargo.toml:

[dependencies]
buco = "0.1"

Example

use buco::Builder;

#[derive(Builder)]
struct Foo {
    a: i32,
    b: i32,
    c: i32,
}

fn main() {
    let foo = Foo::builder()
        .set_a(1)
        .set_b(2)
        .set_c(3)
        .build();

    assert_eq!(foo.a, 1);
    assert_eq!(foo.b, 2);
    assert_eq!(foo.c, 3);
}

Dependencies

~0.7–1.2MB
~26K SLoC