我想知道是否可以使用带枚举的范围匹配器.玩具示例:
enum Things {
One,
Two,
Three
}
pub fn main() {
match One {
One...Two => println!("one to two"),
Three => println!("three")
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
<anon>:9:9: 9:12 error: only char and numeric types are allowed in range [E0029]
<anon>:9 One...Two => println!("one to two"),
^~~
error: aborting due to previous error
playpen: application terminated with error code 101
Run Code Online (Sandbox Code Playgroud)
那么,有可能做出像这样的工作吗?
并不是的.枚举不是订购的.但是,您可以这样做:
enum Things {
One = 1,
Two = 2,
Three = 3
}
pub fn main() {
match One as uint {
1..2 => println!("one to two"),
3 => println!("three")
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
479 次 |
| 最近记录: |