forked from starkware-libs/cairo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum_flow.cairo
58 lines (54 loc) · 1.13 KB
/
enum_flow.cairo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
enum MyEnumShort {
a: felt,
b: felt
}
enum MyEnumLong {
a: felt,
b: felt,
c: felt
}
enum MyEnumGeneric<S, T> {
a: T,
b: S,
c: T
}
impl MyEnumGenericDrop of Drop::<MyEnumGeneric::<(), felt>>;
fn main() -> felt {
let es0 = MyEnumShort::a(10);
match_short(es0);
let es1 = MyEnumShort::b(11);
match_short(es1);
let el0 = MyEnumLong::a(20);
match_long(el0);
let el1 = MyEnumLong::b(21);
match_long(el1);
let el2 = MyEnumLong::c(22);
match_long(el2);
let eg1: MyEnumGeneric::<(), felt> = MyEnumGeneric::<(), felt>::a(30);
let eg2: MyEnumGeneric::<(), felt> = MyEnumGeneric::<(), felt>::b(());
let eg3: MyEnumGeneric::<(), felt> = MyEnumGeneric::<(), felt>::c(32);
300
}
fn match_short(e: MyEnumShort) -> felt {
match e {
MyEnumShort::a(x) => {
x
},
MyEnumShort::b(x) => {
x
},
}
}
fn match_long(e: MyEnumLong) -> felt {
match e {
MyEnumLong::a(x) => {
x
},
MyEnumLong::b(x) => {
x
},
MyEnumLong::c(x) => {
x
},
}
}