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

#55 in No standard library

Download history 817/week @ 2024-03-13 1164/week @ 2024-03-20 1304/week @ 2024-03-27 1305/week @ 2024-04-03 1205/week @ 2024-04-10 1314/week @ 2024-04-17 1142/week @ 2024-04-24 1366/week @ 2024-05-01 1069/week @ 2024-05-08 1623/week @ 2024-05-15 1112/week @ 2024-05-22 1252/week @ 2024-05-29 1640/week @ 2024-06-05 1524/week @ 2024-06-12 1200/week @ 2024-06-19 1218/week @ 2024-06-26

5,877 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

~0.4–0.8MB
~18K SLoC