It’s now time to look at the main ways to build your own types in Rust: structs and enums. You’ll also learn how to implement functions attached to and called on these types, called methods. These methods use the keyword self a lot, so get ready to see it!
Structs and enums have a similar syntax and are easiest to learn together, so that’s what we’ll do here. They also work together because structs can contain enums, and enums can contain structs. Because they look similar, sometimes users new to Rust confuse them. But here’s a rule of thumb to start: if you have a lot of things to group together, that’s a struct, but if you have a lot of choices and need to select one, that’s an enum.
If this book, Learn Rust in a Month of Lunches, were a struct, it would have its own properties, too. It would have a title (that’s a String), an author_name (also a String), and a year_of_publication (maybe an i32). But it also has more than one way to buy it: you can choose to buy it either as a printed book or as an eBook. That’s an enum! So keep that simple example in mind as we learn how structs and enums work.