| 1 | pub struct ChunksArrayDecoder[T] { |
| 2 | callback fn (t T) = unsafe { nil } |
| 3 | } |
| 4 | |
| 5 | pub fn new_chunks_array_decoder[T](callback fn (t T)) &ChunksArrayDecoder[T] { |
| 6 | return &ChunksArrayDecoder[T]{ |
| 7 | callback: callback |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | struct Person { |
| 12 | name string |
| 13 | age int |
| 14 | kgs f32 |
| 15 | } |
| 16 | |
| 17 | @[heap] |
| 18 | struct People { |
| 19 | mut: |
| 20 | persons int |
| 21 | kgs f32 |
| 22 | } |
| 23 | |
| 24 | fn (mut people People) callback(person Person) { |
| 25 | people.persons++ |
| 26 | people.kgs += person.kgs |
| 27 | } |
| 28 | |
| 29 | fn module_callback(person Person) { |
| 30 | println('person: ${person}') |
| 31 | } |
| 32 | |
| 33 | fn test_main() { |
| 34 | mut people := &People{} |
| 35 | mut decoder := new_chunks_array_decoder[Person](people.callback) |
| 36 | _ = decoder |
| 37 | } |
| 38 | |