| 1 | module main |
| 2 | |
| 3 | struct AnyStruct[T] { |
| 4 | val T |
| 5 | } |
| 6 | |
| 7 | fn decode_struct[T]() T { |
| 8 | mut typ := T{} |
| 9 | $for field in T.fields { |
| 10 | typ.$(field.name) = decode_field(typ.$(field.name)) |
| 11 | } |
| 12 | return typ |
| 13 | } |
| 14 | |
| 15 | fn decode_field[T](_ T) T { |
| 16 | mut field := T{} |
| 17 | return field |
| 18 | } |
| 19 | |
| 20 | type Any = int | string | []Any |
| 21 | |
| 22 | fn test_main() { |
| 23 | decode_struct[AnyStruct[Any]]() |
| 24 | decode_struct[AnyStruct[[]Any]]() |
| 25 | } |
| 26 |