None
RS-W1108Checking if a value is None
via a direct comparison is usually inspired
from other programming languages (e.g. foo is None
in Python). In Rust,
the Eq
trait is used to perform the comparison, which is unneeded.
The Option
type provides the is_none()
and is_some()
methods which
return a boolean, allowing for more idoimatic comparison.
fn foo() {
if bar == None {
// ...
}
if bar != None {
// ...
}
}
fn foo() {
if bar.is_none() {
// ...
}
if bar.is_some() {
// ...
}
}