| 1 | struct Struct { |
| 2 | a int |
| 3 | txt string |
| 4 | array []string |
| 5 | } |
| 6 | |
| 7 | fn get_string[T](s T) string { |
| 8 | $for field in T.fields { |
| 9 | $if field.name == 'txt' { |
| 10 | println(field.name) |
| 11 | return s.$(field.name) |
| 12 | } |
| 13 | } |
| 14 | return '' |
| 15 | } |
| 16 | |
| 17 | fn test_main() { |
| 18 | s := Struct{ |
| 19 | txt: 'hello' |
| 20 | } |
| 21 | assert get_string(s) == 'hello' |
| 22 | } |
| 23 |