Struct

A struct in Rust allows you to create a new data type made up of values from other data types. So far, we’ve worked with primitives–things built into the language—​like an i32. But we can combine these primitives into larger, custom types. In this case, I want to define a new data type called Fruit that tells me how many apples and bananas I have. Let’s see what that looks like:

Get hands-on with 1400+ tech skills courses.