Grouping Data with Structs
The treehouse bouncer would like both a name and a customized greeting for every visitor. You could create a new array for greetings, and be careful to add every visitor and their greeting in the same order. That would quickly become tricky to maintain. A better approach is to store all the information about a guest together, in a struct.
A struct is a type that groups data together. Structs contain member fields—variables of (almost) any type. Grouping data together makes it easier to access complicated information—once you’re looking in the right struct, individual pieces of data are available by name.
Structures are ubiquitous in Rust: String and StdIn are both struct types. Rust’s struct types combine related ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access