| 1 | module main |
| 2 | |
| 3 | import strings |
| 4 | |
| 5 | pub struct MyStruct[T] { |
| 6 | pub mut: |
| 7 | result T |
| 8 | } |
| 9 | |
| 10 | pub fn (it MyStruct[T]) indent_str[T]() string { |
| 11 | mut res := strings.new_builder(32) |
| 12 | res.write_string('${it.result}') |
| 13 | return res.str() |
| 14 | } |
| 15 | |
| 16 | fn test_generics_str_intp() { |
| 17 | x := MyStruct[int]{ |
| 18 | result: 100 |
| 19 | } |
| 20 | |
| 21 | y := MyStruct[string]{ |
| 22 | result: 'hello' |
| 23 | } |
| 24 | |
| 25 | assert x.indent_str() == '100' |
| 26 | assert y.indent_str() == 'hello' |
| 27 | } |
| 28 |