The book currently suggests that Default::default is useful for when you want to be generic over construction, but I would argue that that's rarely why you want default, and instead that use case is much better satisfied by taking a closure.
Instead, I think Default is almost exclusively useful for cases like this:
let some_val = MyStruct {
val_a: 1234,
..Default::default()
};
let other_val = MyStruct {
val_c: "other thing",
..some_val,
};
There are some cases where 'default' construction is used as a generic, like on Option::unwrap_or_default, but unsurprisingly I see unwrap_or and unwrap_or_else used far more often.
The book currently suggests that Default::default is useful for when you want to be generic over construction, but I would argue that that's rarely why you want default, and instead that use case is much better satisfied by taking a closure.
Instead, I think Default is almost exclusively useful for cases like this:
There are some cases where 'default' construction is used as a generic, like on Option::unwrap_or_default, but unsurprisingly I see
unwrap_or
andunwrap_or_else
used far more often.