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

#193 in No standard library

Download history 18/week @ 2024-11-13 46/week @ 2024-11-20 48/week @ 2024-11-27 44/week @ 2024-12-04 43/week @ 2024-12-11 14/week @ 2024-12-18 8/week @ 2025-01-01 23/week @ 2025-01-08 43/week @ 2025-01-15 47/week @ 2025-01-22 54/week @ 2025-01-29 83/week @ 2025-02-05 32/week @ 2025-02-12 54/week @ 2025-02-19 24/week @ 2025-02-26

207 downloads per month
Used in 10 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

~260–690KB
~15K SLoC