Rust 为什么不';t选项';是否需要鉴定某些和无变体?
根据选项是一个枚举,其中包含变量Rust 为什么不';t选项';是否需要鉴定某些和无变体?,rust,Rust,根据选项是一个枚举,其中包含变量Some和None 为什么可以引用Some和None而不进行限定 例如,这很好: let x = Option::Some(5); match x { Some(a) => println!("Got {}", a), None => println!("Got None"), } 但这无法编译: enum Foo<T> { Bar(T), Baz, } let x = Foo::Bar(5); match
Some
和None
为什么可以引用Some
和None
而不进行限定
例如,这很好:
let x = Option::Some(5);
match x {
Some(a) => println!("Got {}", a),
None => println!("Got None"),
}
但这无法编译:
enum Foo<T> {
Bar(T),
Baz,
}
let x = Foo::Bar(5);
match x {
Bar(a) => println!("Got {}", a),
Baz => println!("Got Baz"),
}
enum Foo{
巴(T),
巴兹,
}
设x=Foo::Bar(5);
匹配x{
Bar(a)=>println!(“Got{}”,a),
Baz=>println!(“得到了Baz”),
}
编译器的错误是未解析的枚举变量、结构或常量'Bar`
自动插入到每个源文件中的包含以下行:
pub use option::Option::{self, Some, None};
这带来了选项
及其范围内的两个变体