rust

How to write multiple condition in if let statement?


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
    }