Type Safe Builder Pattern

Infallible compile-time checked builders for your structs.

License: GPL v3

No more worrying whether the build call on your builder will return Ok or not. Maybe you forgot to set a field? typesafe-builders solves this by using the Rust type-system to ensure correct usage.

Example

```rust use typesafe_builders::prelude::*;

fn example() { #[derive(Builder)] struct Point { #[builder(constructor)] x: u8, y: u8, #[builder(optional)] z: Option, }

// The `builder` function requires `x` since it is marked as `constructor`.
let builder = Point::builder(1);
// These do not compile:
// partial.x(6);        // `x` is already set
// partial.build();     // `y` is not set

// Set all required fields to enable the `build` function:
let result = builder.y(2).build();

assert_eq!(result.x, 1);
assert_eq!(result.y, 2);
assert_eq!(result.z, None);

} ```

Field Attributes

All attributes must be wrapped in a builder, eg. builder(optional).

How does it work?

Const generic one-hot bitfields. What you get is similar to this:

```rust pub struct Builder { x: Option, y: Option, }

impl Builder { fn set_x(self, x: u8) -> Builder

impl Builder { fn set_y(self, y: u8) -> Builder { todo!() } }

// The build function is only available once all fields are set: impl Builder { fn build() {

}

} ```

TODOs