| 1 | struct Button { |
| 2 | width int |
| 3 | height int |
| 4 | } |
| 5 | |
| 6 | enum Color { |
| 7 | red |
| 8 | blue |
| 9 | yellow |
| 10 | } |
| 11 | |
| 12 | struct ColoredButton { |
| 13 | Button |
| 14 | color Color |
| 15 | } |
| 16 | |
| 17 | fn change_color(cb ColoredButton, color Color) ColoredButton { |
| 18 | return ColoredButton{ |
| 19 | ...cb |
| 20 | color: color |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | fn test_struct_update_with_embed_field() { |
| 25 | red_button := ColoredButton{Button{100, 100}, .red} |
| 26 | blue_button := change_color(red_button, .blue) |
| 27 | |
| 28 | println(red_button) |
| 29 | println(blue_button) |
| 30 | |
| 31 | assert blue_button == ColoredButton{Button{100, 100}, .blue} |
| 32 | } |
| 33 | |