当您不编写枚举模式匹配的完整路径时,为什么编译器不会抱怨?

时间:2019-06-26 19:30:57

标签: rust

当我这样定义枚举时:

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"),
}

如果我明显不正确地匹配枚举,为什么编译器不会显示错误?

0 个答案:

没有答案