feat: if let 语句 — if let Option::Some = expr { ... }
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
enum Option { Some(i64), None }
|
||||
|
||||
fn main() -> i64 {
|
||||
let s = Option::Some(42);
|
||||
let n = Option::None;
|
||||
|
||||
// if let: 匹配 Some
|
||||
if let Option::Some = s {
|
||||
print_i64(100);
|
||||
} else {
|
||||
print_i64(0);
|
||||
}
|
||||
|
||||
// if let: 匹配 None(走 else)
|
||||
if let Option::Some = n {
|
||||
print_i64(999);
|
||||
} else {
|
||||
print_i64(200);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user