From the course: Rust Essential Training

Unlock the full course today

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

Defining structs

Defining structs - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Defining structs

- Tuples are useful when we need to concisely package a couple of related values together. But, the fact that their values are stored and accessed based on their relative order, means if there are a lot of elements and their order isn't obvious. It can be tedious keeping track of which item is first, second, third, and so on. When you need to access them. That's where a struct can be useful. A struct or structure is like a tuple, in that it allows you to package together related values of different data types. But unlike a tuple, you assign a name to each value to indicate what it means and you use that name to access it. That means you don't have to worry about the order in which those elements are stored. To define a new custom struct data type we'll use the keyword struct followed by the name of the struct. Let's define a struct to represent a space shuttle. It's common to capitalize the name for a custom struct…

Contents