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:
if let 1 | 2 | 3 = n { println!("found in pattern") }
I thought the second if letdesugared:
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
source
share