How to modify if let statement so it also handles another condition like Some(7) == b?
let a = Some(6);
let b = Some(7);
if let Some(6) = a /* && Some(7) = b */{
// do something
}
How to modify if let statement so it also handles another condition like Some(7) == b?
let a = Some(6);
let b = Some(7);
if let Some(6) = a /* && Some(7) = b */{
// do something
}
The if let expression only admits one match arm pattern against one expression. However, they can be merged together into a single equivalent pattern match condition. In this case, the two Option values can be combined into a pair and matched accordingly.
if let (Some(6), Some(7)) = (a, b) {
// do something
}
See also: