Syntax: fn type name

This commit is contained in:
2026-06-16 03:29:01 +02:00
parent eea72f5bb3
commit aadccb7f38
15 changed files with 9 additions and 842 deletions
-62
View File
@@ -1,62 +0,0 @@
pub module enum_test;
enum OptionInt {
None,
Some[i32],
}
pub fn test_enum_named() {
let x = OptionInt::None;
match x {
OptionInt::None => { assert_eq!(1, 1); }
OptionInt::Some[_] => { assert_eq!(0, 1); }
}
}
pub fn test_enum_tuple() {
let x = OptionInt::Some(42);
match x {
OptionInt::None => { assert_eq!(0, 1); }
OptionInt::Some[v] => { assert_eq!(v, 42); }
}
}
enum Shape {
Circle { radius i32 },
Rect { w i32, h i32 },
}
pub fn test_enum_struct() {
let c = Shape::Circle { radius: 5 };
match c {
Shape::Circle { radius } => { assert_eq!(radius, 5); }
Shape::Rect { .. } => { assert_eq!(0, 1); }
}
let r = Shape::Rect { w: 3, h: 4 };
match r {
Shape::Circle { .. } => { assert_eq!(0, 1); }
Shape::Rect { w, h } => { assert_eq!(w * h, 12); }
}
}
enum Color {
Red,
Green,
Blue,
}
pub fn test_enum_eq() {
let c = Color::Red;
match c {
Color::Red => { assert_eq!(1, 1); }
_ => { assert_eq!(0, 1); }
}
}
pub fn run_tests() {
test_enum_named();
test_enum_tuple();
test_enum_struct();
test_enum_eq();
}