Build Status Latest Version Rust Documentation

Rust Typed Builder

Creates a compile-time verified builder:

```rust

[macro_use]

extern crate typed_builder;

[derive(TypedBuilder)]

struct Foo { // Mandatory Field: x: i32,

// #[builder(default)] without parameter - use the type's default
#[builder(default)]
y: Option<i32>,

// Or you can set the default
#[builder(default=20)]
z: i32,

// If the default cannot be parsed, you must encode it as a string.
// This also allows you to refer to the values of earlier-declared fields.
#[builder(default_code="vec![z as u32, 40]")]
w: Vec<u32>,

} ```

Build in any order: rust Foo::builder().x(1).y(2).z(3).w(vec![4, 5]).build(); Foo::builder().z(1).x(2).w(vec![4, 5]).y(3).build();

Omit optional fields(the one marked with #[default]): rust Foo::builder().x(1).build()

But you can't omit non-optional arguments - or it won't compile: rust Foo::builder().build(); // missing x Foo::builder().x(1).y(2).y(3); // y is specified twice

Features

Limitations

Alternatives - and why typed-builder is better

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.