Struct
We'll cover the following...
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:
Press + to interact
struct Fruit {apples: i32,bananas: i32,}
struct
starts a declaration, similar to how fn
starts a declaration. In ...
Access this course and 1400+ top-rated courses and projects.