| 1 | module main |
| 2 | |
| 3 | import json |
| 4 | |
| 5 | pub enum PlatformType { |
| 6 | unknown |
| 7 | osx |
| 8 | ubuntu |
| 9 | alpine |
| 10 | } |
| 11 | |
| 12 | pub enum CPUType { |
| 13 | unknown |
| 14 | intel |
| 15 | arm |
| 16 | intel32 |
| 17 | arm32 |
| 18 | } |
| 19 | |
| 20 | @[heap] |
| 21 | pub struct Node { |
| 22 | pub: |
| 23 | name string = 'mymachine' |
| 24 | pub mut: |
| 25 | platform PlatformType |
| 26 | cputype CPUType |
| 27 | done map[string]string |
| 28 | environment map[string]string |
| 29 | } |
| 30 | |
| 31 | pub fn (mut node Node) save() ! { |
| 32 | data := json.encode(node) |
| 33 | dump(data) |
| 34 | } |
| 35 | |
| 36 | fn test_encode_with_mut_struct() { |
| 37 | mut n := Node{ |
| 38 | platform: .osx |
| 39 | cputype: .unknown |
| 40 | } |
| 41 | n.save() or { panic(err) } |
| 42 | } |
| 43 | |