从技术上来说没有,但你可以捎带Option总是可用来实现类似效果的枚举:
fn opt_arg(i: Option<int>) {
match i {
Some(x) => { println!("Got {}", x); },
None => { println!("Didn't get anything"); }
}
}
fn main() {
opt_arg(None); // Didn't get anything
opt_arg(Some(2i)); // Got 2
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
402 次 |
| 最近记录: |