| 1 | module main |
| 2 | |
| 3 | struct Bar { |
| 4 | name string |
| 5 | } |
| 6 | |
| 7 | struct Foo { |
| 8 | bars []Bar |
| 9 | } |
| 10 | |
| 11 | fn (f Foo) find() ?&Bar { |
| 12 | return &f.bars[1] or { return none } |
| 13 | } |
| 14 | |
| 15 | fn test_main() { |
| 16 | foo := Foo{ |
| 17 | bars: [Bar{ |
| 18 | name: '123' |
| 19 | }, Bar{ |
| 20 | name: 'aaa' |
| 21 | }, Bar{ |
| 22 | name: 's34' |
| 23 | }] |
| 24 | } |
| 25 | bar := foo.find() or { panic('not found') } |
| 26 | println(bar.name) |
| 27 | assert bar.name == 'aaa' |
| 28 | } |
| 29 |