当我这样定义枚举时:
enum MyEnum {
one,
two,
three,
}
并匹配如下:
let n = MyEnum::two;
match n {
one => println!("one"),
two => println!("one"),
three => println!("three"),
}
它将始终打印one
。正确的匹配方式如下:
let n = MyEnum::two;
match n {
MyEnum::one => println!("one"),
MyEnum::two => println!("one"),
MyEnum::three => println!("three"),
}
如果我明显不正确地匹配枚举,为什么编译器不会显示错误?