Closed
Description
What it does
Suggest using Option::unwrap_or_default
when Option::unwrap_or_else
is called using a function that creates the default.
Categories (optional)
- Kind: style
Makes the code shorter and more idiomatic.
Drawbacks
None.
Example
let x : Option<_> = ...
x.unwrap_or_else(Vec::new)
Could be written as:
let x : Option<_> = ...
x.unwrap_or_default()
Requires an understanding of what closures produce default values - e.g. Vec::default
, Default::default
, Vec::new
, || Vec::new()
.