Closed 2moe closed 7 months ago
Just do it the other way around - define the Default
using the builder:
#[derive(Debug, TypedBuilder)]
struct Foo {
#[builder(default = 100)]
n: u8,
}
impl Default for Foo {
fn default() -> Self {
Self::builder().build()
}
}
Thanks
As in the example above, I want the default to be
Foo::default().n
, notu8::default()
.The behavior is like
#[serde(default)]
.Aside from manually specifying
Foo::default().n
, is there an easier way to specify the default value as the default value of the field corresponding to the structure itself, rather than the default value of the field type?