From the course: First Look: Rust

Unlock the full course today

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

Using structs

Using structs - Rust Tutorial

From the course: First Look: Rust

Start my 1-month free trial

Using structs

[Instructor] A struct or structure is a custom data type that lets us name and package together multiple rated values that make up a meaningful group. If you're familiar with an object oriented language a struct is like an object's data attributes. The struct and enum concepts are the binding blocks of creating new types in a programs domain to take full advantage of Rust compile time type checking. Structs are similar to tupual. Like tupuals, the pieces of a struct can be of different types. Let's create a new project and call it structs. (typing) Let's get into the project (typing) and on visual studio code you should see the main.rs file created for you. Let's remove the standard println statement. Let's declare our first struct and call it user. The struct goes inside the main function. (typing) The struct contains username and email which is of string types. So let me say username followed by a colon. And a string type which is then followed by a comma and then the email of that…

Contents