Closed
Description
What it does
Suggests using opt.is_none_or(...)
instead of !opt.is_some_and(...)
, also suggests to invert the boolean expression inside the closure to keep the two equivalent.
I can imagine some algorithm that will try to invert the expression in the 'nicest' way, converting (just examples)
a < b
toa >= b
a == b
toa != b
result.is_ok()
toresult.is_err()
!(expr)
toexpr
- Finally, if the above do not work for a specific expression, just put a
!
in front of the expression, and parentheses around it if necessary.
If a function pointer is passed in, convert it to a closure and put !
in front of it (|args| !function(args)
).
Advantage
- Convert harder to read
!(option is some && some expression)
tooption is none || !(some expression)
.
Drawbacks
- This can introduce unnecessary closures (see last line of "What it does").
Example
!opt.is_some_and(|x| x >= 1000)
Could be written as:
opt.is_none_or(|x| x < 1000)