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

#126 in No standard library

Download history 1645/week @ 2024-07-20 1819/week @ 2024-07-27 1873/week @ 2024-08-03 1691/week @ 2024-08-10 1511/week @ 2024-08-17 1421/week @ 2024-08-24 1577/week @ 2024-08-31 1329/week @ 2024-09-07 1603/week @ 2024-09-14 1782/week @ 2024-09-21 1618/week @ 2024-09-28 1293/week @ 2024-10-05 99/week @ 2024-10-12 40/week @ 2024-10-19 36/week @ 2024-10-26 30/week @ 2024-11-02

299 downloads per month
Used in 11 crates (4 directly)

MIT/Apache

11KB
106 lines

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

~310–760KB
~17K SLoC