I have a Rust struct with a large number of fields, all of which are themselves Default. I'd like to create a custom impl Default for it, with the following semantics:
- One of the fields has a custom value
- All other fields get their value from their
Default::default
Here's how I hoped to do that:
impl Default for Foo {
fn default() -> Self {
Self {
thing: 2,
..Default::default()
}
}
}
...but that actually causes unchecked recursion, since ..Default::default() calls Self::default() rather than $member::default() for each member of Self.
Is there any way to accomplish this, short of writing a custom macro or explicitly listing every field?