feat: if let 语句 — if let Option::Some = expr { ... }

This commit is contained in:
2026-06-06 15:20:34 +08:00
parent 0e1f8c5795
commit e02cc7b1d6
4 changed files with 98 additions and 39 deletions
+22
View File
@@ -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;
}