builder_option

Crates.iobuilder_option
lib.rsbuilder_option
version0.1.0
sourcesrc
created_at2024-10-27 19:12:07.040388
updated_at2024-10-27 19:12:07.040388
descriptionA macro to generate builder class for a struct
homepagehttps://andrzej.lichnerowicz.pl
repositoryhttps://codeberg.org/unjello/builder_option
max_upload_size
id1424893
size17,557
Andrzej Lichnerowicz (unjello)

documentation

README

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

Commit count: 0

cargo fmt