2 releases

Uses old Rust 2015

0.1.1 Apr 21, 2017
0.1.0 Apr 21, 2017

#45 in #builder

MIT license

416 lines

You woudn't call unwrap on a constructer!

A proc-macro for deriving a type-safe builder pattern on any struct*


extern crate safe_builder;
extern crate safe_builder_derive;

use safe_builder::*;

struct Person
    name: String,
    age: usize,
    //        town    street  number
    address: (String, String, usize)

fn main()
    let me: Person = Person::build()
        .name("Matthew M.".to_owned())
        .address(("Toronto".to_owned(), "Younge st.".to_owned(), 0));
    // no need to call unwrap - the compiler knows that the type is complete
    let you = Person::build()
        .age(0) // hello, world!
        .address(("City".to_owned(), "Street".to_owned(), 0))
    // build your structs in any order!
    Wont compile: the type is incomplete
    let no_name: Person = Person::build()
        .address((String::new(), String::new(), 0));

Please use this crate on your most complicated structs, and open some issues when you find bugs!

*no generic struct or those with lifeties, yet


~45K SLoC