Suppose f()
and g()
return Option<T>
.
if let (Some(x), Some(y)) = (f(), g()) {
h();
}
If f()
returns None
, will g()
be evaluated? Is evaluation guaranteed or prohibited by the spec?
It does not shortcut. To pattern-match against the pair, the pair must be fully constructed, which means both f
and g
have been called. There is no lazy evaluation where the pattern match could happen before the values are calculated.
(By the way, it's easy to try out, and the Rust compiler pretty much is the spec right now.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With