1 unstable release

0.1.0 Oct 27, 2024

#1809 in Procedural macros

Download history 112/week @ 2024-10-25 23/week @ 2024-11-01 5/week @ 2024-11-08 3/week @ 2024-11-15

143 downloads per month
Used in builder_option

CC0 license

7KB
113 lines

builder!

A macro, or two, to simplify usage of builder pattern on structs.

use builder_option::Builder;

#[derive(Debug, Builder)]
pub struct Client {
    pub field: bool,
    pub another: Option<bool>,
    pub optional: Option<String>,
}

fn main() -> Result<(), dyn std::error::Error> {
    let client = Client::builder()
        .with_field(true)
        .with_another(false),
        .build()?;
    
    assert!(client.field);
    assert_eq!(client.another, false);
    assert!(client.optional.is_none());
}

LICENSE


lib.rs:

This crate contains a proc-macro Builder that creates a builder for an annotated struct. It's in a separate crate, because Rust does not allow for proc-macro crates to contain macros-by-example.

See builder_option for details.

Dependencies

~210–650KB
~15K SLoC