feat: 枚举关联数据 ADT — enum Option { Some(i64), None }

This commit is contained in:
2026-06-06 14:21:43 +08:00
parent 0ec3c3d65f
commit 0e1f8c5795
9 changed files with 172 additions and 37 deletions
+17
View File
@@ -0,0 +1,17 @@
enum Option { Some(i64), None }
fn main() -> i64 {
let s = Option::Some(42);
let n = Option::None;
// 打印 tag 值 (Some=0, None=1)
print_i64(s);
print_i64(n);
// match 判断是 Some 还是 None(只比较 tag
match s {
Option::None => { print_i64(999); }
_ => { print_i64(100); }
}
return 0;
}