Default is the Rust trait for constructing a fallback value of a type. Implementing it defines that type’s default value. Common built-in defaults include 0 for numbers, an empty String, false for Booleans, and None for Option. section 8.3
A builder can use Default instead of panicking when a field is missing. With a builder_defaults attribute, generated code calls unwrap_or_default(); without it, generated code retains an expect-based missing-field failure. section 8.3
Using defaults in a builder
A derived builder can fill omitted fields when the attribute is present: #[derive(Builder)] #[builder_defaults] struct ExampleStructTwoFields { string_value: String, int_value: i32, } let example = ExampleStructTwoFields::builder().build(); assert_eq!(example.string_value, String::default()); assert_eq!(example.int_value, Default::default());
Default-based generated code has two important constraints:
- A procedural macro can improve that diagnostic by generating field-specific where clauses with core::default::Default and applying the offending type’s span. section 8.4

