Skip to content

jooris-hadeler/builder_macro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Builder Macro

Builder Macro is a proc macro that automatically derives a Builder for any struct.

Usage

use builder_macro::Builder;

#[derive(Debug, Builder)]
pub struct Point<X, Y> 
where 
    X: Debug + Default,
    Y: Debug + Default,
{
    x: X,
    // This will automatically set a default value for `y`.
    #[builder(default = Default::default())]
    y: Y,
    // This will be skipped by the builder.
    #[builder(skip, default = false)]
    opt: bool,
}

fn main() {
    let point = Point::<i32, i32>::builder()
        .with_x(12)
        .build() // Build returns an Err(msg) if a field is missing.
        .unwrap();

    println!("{point:?}");
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages