I am currently trying to do small first steps into Rust but can't seem to get deserializing anything else than most basic toml-structures into custom structs right. I think I don't fully understand the way toml-rs parses e.g. nested structures into custom structs and could use some help.
Suppose I got this .toml-file:
balls = 5
bricks = 250
[cars]
[cars.car1]
color = "green"
speed = 3
[cars.car2]
color = "red"
speed = 10
[trucks]
[trucks.truck1]
load = 15
hp = 670
[trucks.truck2]
load = 25
hp = 800
Where all (sub-)sections are required, e.g. no Option<...> to keep it simple. How would a custom structure look that this .toml could be deserialized to? I tried the following, but this does not work:
This produces runtime errors when I try to deserialize the example .toml into this structure-setup. What would I need to change in order to deserialize the nested parts correctly? Where am I thinking wrong at the moment?
I'm not sure exactly how far you got to, but what you have is pretty close, except that the rust representation for that toml would use a HashMap<String,Car> for cars and a similar construct for trucks (ie cars and trucks are a map instead of a vector). Here's a working example