v / vlib / v2 / gen / cleanc / tests / map_enum_shorthand_keys.v
29 lines · 25 sloc · 350 bytes · 09cc0c5133d075ee6dcff29286dce7eb7d4421da
Raw
1module main
2
3enum State {
4 idle
5 run
6}
7
8fn make_explicit() map[State]int {
9 return {
10 .idle: 10
11 .run: 20
12 }
13}
14
15fn make_from_context() map[State]int {
16 return {
17 .idle: 30
18 .run: 40
19 }
20}
21
22fn main() {
23 a := make_explicit()
24 b := make_from_context()
25 println(a[State.idle])
26 println(a[State.run])
27 println(b[State.idle])
28 println(b[State.run])
29}
30