Closed
Description
What it does
Replace a if-then with the use of bool::then_some.
Advantage
Sometimes it could simplify the code.
Drawbacks
It uses less common methods instead of basic language constructs, so it makes the code a little less simple.
Example
pub fn foo(b: bool, x: u32) -> Option<u32> {
if b {
Some(x)
} else {
None
}
}
Could be written as:
pub fn bar(b: bool, x: u32) -> Option<u32> {
b.then_some(x)
}