Open
Description
What it does
get_or_insert_with
followed by unwrap function can be replaced by unwrap_or_else
.
unwrap function:
unwrap
except
unwrap_unchecked
Lint Name
manual_option_folding
Category
style
Advantage
- Remove
unsafe
block forunwrap_unchecked
. - More idiomatic.
Drawbacks
No response
Example
// foo: impl Fn() -> X
// def: impl Fn() -> X
let mut opt: Option<X> = foo();
opt.get_or_insert_with(|| def());
let res: X = unsafe { opt.unwrap_unchecked() };
Could be written as:
let res: X = foo().unwrap_or_else(|| def());