HiveBrain v1.2.0
Get Started
← Back to all entries
snippetrustMajor

How to write multiple condition in if let statement?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
conditionhowstatementletwritemultiple

Problem

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
}

Solution

You can use a simple tuple:

if let (Some(6), Some(7)) = (a, b) {
    // do something
}

Code Snippets

if let (Some(6), Some(7)) = (a, b) {
    // do something
}

Context

Stack Overflow Q#64293804, score: 93

Revisions (0)

No revisions yet.