| 1 | struct Papa { |
| 2 | fam_name string |
| 3 | } |
| 4 | |
| 5 | pub struct Child { |
| 6 | Papa |
| 7 | pub mut: |
| 8 | activity Activity = Fun.roll |
| 9 | age u8 = 2 |
| 10 | } |
| 11 | |
| 12 | type Activity = Fun | Other |
| 13 | |
| 14 | pub enum Fun { |
| 15 | run |
| 16 | roll |
| 17 | jump |
| 18 | } |
| 19 | |
| 20 | pub struct Other {} |
| 21 | |
| 22 | // Same struct without embedding just works. |
| 23 | pub struct Human { |
| 24 | fam_name string |
| 25 | pub mut: |
| 26 | activity Activity = Fun.roll |
| 27 | age u8 = 2 |
| 28 | } |
| 29 | |
| 30 | fn test_embed_struct_field_default_value() { |
| 31 | c := Child{} |
| 32 | println(c.activity) |
| 33 | assert c.activity == Activity(Fun.roll) |
| 34 | h := Human{} |
| 35 | println(h.activity) |
| 36 | assert h.activity == Activity(Fun.roll) |
| 37 | } |
| 38 | |