#builder #staged #telescopic

no-std staged-builder

A proc macro which generates staged builders for types

4 releases

0.2.0 Feb 11, 2024
0.1.2 Mar 20, 2023
0.1.1 Mar 6, 2022
0.1.0 Feb 6, 2022

#68 in No standard library

Download history 22/week @ 2023-11-01 26/week @ 2023-11-08 29/week @ 2023-11-15 19/week @ 2023-11-22 28/week @ 2023-11-29 17/week @ 2023-12-06 25/week @ 2023-12-13 14/week @ 2023-12-20 27/week @ 2023-12-27 14/week @ 2024-01-03 160/week @ 2024-01-10 37/week @ 2024-01-17 23/week @ 2024-01-24 195/week @ 2024-01-31 237/week @ 2024-02-07 83/week @ 2024-02-14

565 downloads per month
Used in 3 crates (2 directly)

MIT/Apache

11KB
106 lines

staged-builder

Documentation

A proc macro which generates staged builders for types.

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.


lib.rs:

A procedural macro which creates a "staged" builder for a type.

Staged (also known as telescopic) builders are a style of infallible builders; code will not compile if any required fields are not set. Specifically, the builder advances in order through a sequence of "stage" types, each corresponding to a required field of the struct. The final stage has setters for all optional fields and the final .build() method.

See the documentation for #[staged_builder] for more details.

Examples

use staged_builder::staged_builder;

#[staged_builder]
struct Person {
    #[builder(into)]
    name: String,
    age: u32,
    #[builder(list(item(type = Person)))]
    parents: Vec<Person>,
}

let person = Person::builder()
    .name("John Doe")
    .age(25)
    .build();

Dependencies

~0.4–0.9MB
~20K SLoC