| 1 | type Async_cb = fn (x []u8, mut y []u8) int |
| 2 | |
| 3 | fn async_cb(b []u8, mut res []u8) int { |
| 4 | if b.len > 0 { |
| 5 | res << b |
| 6 | } |
| 7 | return 0 |
| 8 | } |
| 9 | |
| 10 | struct Ep_arg { |
| 11 | mut: |
| 12 | sfd int |
| 13 | cb Async_cb |
| 14 | } |
| 15 | |
| 16 | fn test_struct_fn_field_can_be_used_directly() { |
| 17 | buf := [u8(1), 2, 3] |
| 18 | mut res := []u8{} |
| 19 | res << 0x88 |
| 20 | async_cb(buf[0..2], mut res) |
| 21 | data := Ep_arg{ |
| 22 | sfd: 1234 |
| 23 | cb: async_cb |
| 24 | } |
| 25 | data.cb(buf[1..2], mut res) |
| 26 | res << 0x99 |
| 27 | eprintln(res) |
| 28 | assert res == [u8(0x88), 0x01, 0x02, 0x02, 0x99] |
| 29 | } |
| 30 | |