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    /// Custom doc comment.
14    /// Multiline.
15    #[builder(default = (2 + 2) * 10)]
16    small_custom_default: u32,
17
18    /// Custom doc comment.
19    /// Multiline.
20    #[builder(default = Vec::from([
21        Point { x: 1, y: 2 },
22        Point { x: 3, y: 4 },
23        Point { x: 5, y: 6 },
24        Point { x: 7, y: 8 },
25    ]))]
26    big_custom_default: Vec<Point>,
27
28    #[builder(default)]
29    standard_u32_default: u32,
30
31    #[builder(default)]
32    standard_string_default: String,
33}
34
35pub struct Point {
36    x: u32,
37    y: u32,
38}