Crates.io | builder_option |
lib.rs | builder_option |
version | 0.1.0 |
source | src |
created_at | 2024-10-27 19:12:07.040388 |
updated_at | 2024-10-27 19:12:07.040388 |
description | A macro to generate builder class for a struct |
homepage | https://andrzej.lichnerowicz.pl |
repository | https://codeberg.org/unjello/builder_option |
max_upload_size | |
id | 1424893 |
size | 17,557 |
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());
}