bon_sandbox/
attr_default.rs

1#[derive(bon::Builder)]
2#[builder(builder_type(
3    doc {
4        /// Showcases examples of `#[builder(default)]` usage and what docs are
5        /// generated for them. Click on any of `source` links to see the source code.
6    },
7))]
8#[allow(
9    clippy::struct_field_names,
10    reason = "Common `_default` suffix is for better readability"
11)]
12pub struct Example {
13    #[builder(default = (2 + 2) * 10)]
14    small_custom_default: u32,
15
16    #[builder(default = Vec::from([
17        Point { x: 1, y: 2 },
18        Point { x: 3, y: 4 },
19        Point { x: 5, y: 6 },
20        Point { x: 7, y: 8 },
21    ]))]
22    big_custom_default: Vec<Point>,
23
24    #[builder(default)]
25    standard_u32_default: u32,
26
27    #[builder(default)]
28    standard_string_default: String,
29}
30
31pub struct Point {
32    x: u32,
33    y: u32,
34}