From the course: Rust Essential Training
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Tuple structs - Rust Tutorial
From the course: Rust Essential Training
Tuple structs
- [Instructor] We've learned about tuples and we've learned about structs. Now, let's talk about tuple structs, which exist somewhere between those two data types. Tuple structs are defined to look similar to tuples in that they don't have names associated with their fields, just the data type of the fields. But, they have the advantage of being distinguishable as a unique data type, like structs. This can be convenient when you want to give a whole tuple a name to differentiate it from other tuples, but naming every field, like in a regular struct, would be overkill and verbose. An example of this would be a tuple that represents a color. Computers commonly represent colors as a sequence of three values representing the amount of red, green and blue that make up the overall color. It's standard for those values to be listed in that order, so it would be redundant to name each field. We can define a tuple struct to represent…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.