如果让多个模式不起作用

Pao*_*lla 7 rust

您可以使用if let模式匹配范围:

let n=1
if let 1...3 = n { println!("found in range") }
Run Code Online (Sandbox Code Playgroud)

但我不能让它适用于多种模式:

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

我以为第二个if let去了:

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

什么赋予了什么?我使用了错误的语法吗?我是否期望多种模式应该被误导?这只是没有实现?

操场

DK.*_*DK. 8

if let只是不支持多种模式(参见RFC issue 935).请match改用.