forked from starkware-libs/cairo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
enum_flow.cairo
48 lines (44 loc) · 1.07 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
enum MyEnumShort {
a: felt252,
b: felt252
}
enum MyEnumLong {
a: felt252,
b: felt252,
c: felt252
}
enum MyEnumGeneric<S, T> {
a: T,
b: S,
c: T
}
impl MyEnumGenericDrop of Drop<MyEnumGeneric<(), felt252>>;
fn main() -> felt252 {
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<(), felt252> = MyEnumGeneric::<(), felt252>::a(30);
let _eg2: MyEnumGeneric<(), felt252> = MyEnumGeneric::<(), felt252>::b;
let _eg3: MyEnumGeneric<(), felt252> = MyEnumGeneric::<(), felt252>::c(32);
300
}
fn match_short(e: MyEnumShort) -> felt252 {
match e {
MyEnumShort::a(x) => { x },
MyEnumShort::b(x) => { x },
}
}
fn match_long(e: MyEnumLong) -> felt252 {
match e {
MyEnumLong::a(x) => { x },
MyEnumLong::b(x) => { x },
MyEnumLong::c(x) => { x },
}
}