| 1 | struct IntArray { |
| 2 | a []int |
| 3 | } |
| 4 | |
| 5 | fn encode_array[U](val []U) []string { |
| 6 | mut out := []string{} |
| 7 | $if U is int { |
| 8 | out << 'is int' |
| 9 | } $else $if U is $struct { |
| 10 | out << 'is struct' |
| 11 | } |
| 12 | return out |
| 13 | } |
| 14 | |
| 15 | fn encode_struct[U](val U) ?[]string { |
| 16 | $for field in U.fields { |
| 17 | if field.is_array { |
| 18 | value := val.$(field.name) |
| 19 | return encode_array(value) |
| 20 | } |
| 21 | } |
| 22 | return none |
| 23 | } |
| 24 | |
| 25 | fn test_main() { |
| 26 | int_array := IntArray{ |
| 27 | a: [1, 2, 3] |
| 28 | } |
| 29 | assert encode_struct(int_array)?.str() == "['is int']" |
| 30 | } |
| 31 | |