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.
```rust
fn example() {
#[derive(Builder)]
struct Point {
x: u8,
y: u8,
#[optional]
z: Option
let builder = Point::builder();
let partial = builder.x(5);
// 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 complete = partial.y(8);
let result = complete.build();
assert_eq!(result.x, 5);
assert_eq!(result.y, 8);
assert_eq!(result.z, None);
} ```
#[optional]
- WIP: to be changed to builder(optional)
to prevent name clashes.Const generic one-hot bitfields. What you get is similar to this:
```rust
pub struct Builder
impl impl // The build function is only available once all fields are set:
impl Builder }
```}
TODOS
optional
fields.rename
field attribute.in_constructor
or something like this to have mandatory args directly in the builder
function.Into
or whatever to cast types.Some
automatically.