From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Tuple structs

Tuple structs - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

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…

Contents