How to define multi layered data

Hello all,
I am a rust newbie, in the extreme. I am trying to "define" some data that has several layers, and I am having no success. Here's an example of what I am looking at. In sports there are a lot of statistics that are keep. Lets say baseball. Caps or for emphasis only. So we have the top level, BASEBALL, next we have TEAMS which would probable be a vector, with other fields say date of origin, mascot, and so on. Next layer, COACH with name, years experience, age, next layer, SUBCOACH, a vector also since there would be more than one sub coach, along with age, years of coaching, other areas of expertise. Next layer we'll do PLAYERS. They too would be vectors under the sub coach, they may have other fields too, like age, batting average, year of play, positions played and so on and so on. We see multiple layers here with vectors, strings, and integers, or we'll say multiple data types. I have no idea how to define such a data "structure" in rust. It is not important what the data may be, but how to construct such a layout. Thanks for any and all thoughts. Remember I am a newbie with rust so try not to use definitions I may not understand yet. If you include an example please use all layers not just one or two. I have written a hand full of very small rust programs, and now looking for something a bit larger. Thanks again.


This is "just" hierarchical data, right? That is usually represented by nesting your types within one another, like this:

struct Baseball {
    teams: Vec<Team>,

struct Team {
    name: String,
    mascot_name: String,
    coach: Coach,

struct Coach {
    name: String,
    experience_years: u32,
    subcoaches: Vec<SubCoach>,

// etc.
1 Like

Thanks H2CO3,

Yes, the data is just hierarchical. I have tried something similar to what you show, but let me work with your example for a while and see if I can get it working. One last thing. down in the code, do I need to use each level name to get to a lower level or just ""?

Interesting name H2CO3, does it mean anything? Just curious.

Thanks for the help


For questions about basic Rust syntax, please see the book.

H2CO3 is the chemical formula of carbonic acid:

1 Like

Thanks for the info.
I think I am on the right track now. I just couldn't get the structures to work. It wasn't the structures of course it was me and my way of thinking.

Thanks again


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.