| 1 | struct FixedStruct1 { |
| 2 | a int |
| 3 | b string |
| 4 | c ?int |
| 5 | d ?string |
| 6 | } |
| 7 | |
| 8 | fn encode_struct[T](val T) []string { |
| 9 | mut out := []string{} |
| 10 | $for field in T.fields { |
| 11 | value := val.$(field.name) |
| 12 | $if field.is_option { |
| 13 | gg := value ? |
| 14 | println(gg) |
| 15 | out << '${gg}' |
| 16 | } $else { |
| 17 | gg := value |
| 18 | println(gg) |
| 19 | out << gg.str() |
| 20 | } |
| 21 | } |
| 22 | return out |
| 23 | } |
| 24 | |
| 25 | fn test_main() { |
| 26 | out := encode_struct(FixedStruct1{1, 'foo', 4, 'bar'}) |
| 27 | assert out[0] == '1' |
| 28 | assert out[1] == 'foo' |
| 29 | assert out[2] == '4' |
| 30 | assert out[3] == 'bar' |
| 31 | } |
| 32 |