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

#54 in No standard library

Download history 6/week @ 2024-01-25 196/week @ 2024-02-01 139/week @ 2024-02-08 14/week @ 2024-02-15 21/week @ 2024-02-22 19/week @ 2024-02-29 167/week @ 2024-03-07 907/week @ 2024-03-14 1216/week @ 2024-03-21 1334/week @ 2024-03-28 1289/week @ 2024-04-04 1178/week @ 2024-04-11 1352/week @ 2024-04-18 1239/week @ 2024-04-25 1172/week @ 2024-05-02 1137/week @ 2024-05-09

5,097 downloads per month
Used in 3 crates (2 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
~19K SLoC