Closed
Description
What it does
Checks for if-else that could be rewritten to bool::then
Categories (optional)
- Kind:
stylerestriction
Reduces redundancy and lines of code by leveraging a new stable API bool::then
Drawbacks
None.
Example
let a = if foo {
println!("hello foo!");
Some(bar())
} else {
None
};
Could be written as:
let a = foo.then(|| {
println!("hello foo!");
bar()
});
Note that the following cannot be rewritten using bool::then
because it has some action in else
block:
let a = if foo {
println!("hello foo!");
Some(bar())
} else {
println!("else!");
None
};