builder_option_derive 0.1.0

A macro to generate builder class for a struct
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 7.26 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 284.03 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • unjello

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