How do I conditionally execute code only when an Option is None?
If you are not interested in the value, just use
if v.is_none() { ... }
To check if an Option
is None
you can either use Option::is_none
or use the if let
syntax.
For example:
let x = ffunc();
if let None = x {
println!("x is None")
}
Or using the Option::is_none
function:
let x = ffunc();
if x.is_none() {
println!("x is None")
}