v2 / vlib / v / checker / tests / comptime_assign_missing_mut_err.vv
21 lines · 17 sloc · 328 bytes · c06fd556e8f01f65eeda1d499620eca3a3be5df4
Raw
1import toml
2
3struct Person {
4 name string
5}
6
7fn decode[T](toml_str string) !T {
8 res := T{}
9 doc := toml.parse_text(toml_str)!.to_any()
10 $for field in T.fields {
11 val := doc.value(field.name)
12 $if field.typ is string {
13 res.$(field.name) = val.string()
14 }
15 }
16 return res
17}
18
19p_str := 'name = "John"'
20
21decode[Person](p_str)!
22