Several templates do not work if they allow

You can use if letto match the pattern in the range:

let n=1
if let 1...3 = n { println!("found in range") }

but I can't get it to work with multiple templates:

// this does not compile
if let 1 | 2 | 3 = n { println!("found in pattern") }
//      -^ unexpected token

I thought the second if letdesugared:

// this does compile and work
match n {
    1 | 2 | 3 => println!("found in pattern"),
    _ => {}
}

so what gives? Am I using the wrong syntax? Is my expectation that multiple templates should work just wrong? Is it just not implemented?

playground

+6
source share
1 answer

if letjust doesn't support multiple patterns (see RFC-release 935 ). Use instead match.

+8
source

All Articles