Struck.
Which are short for structures, let you name and package together related values into a single value
so that you can deal with them as a single unit.
Rust has three types of structs a named field tuple like and a unit like.
Named Field Drug gives a name to each component.
A tuple like struc identifies them by the order in which they appear, and a unit like struc actually
has no components at all, which might sound trivial, but we'll be able to make sense of that a little
bit later on.
But for now, let's start and look at a named field.
So we create a struct by using the struct keyword and then the name that we want our drug to be.
So notice that it is capitalized at the first character.
This is known as Camel Case or Pasqual case.
And as the desired format that Rust calls for in this situation.
So we're creating a struct called user and now we're going to give it some.
Attributes and notice how these are key pair values when we do this.
So we're going to have active and it's going to be a boolean.
We're going to have username as a string and then we're going to say the sign and count and it'll be
an unsigned 32 integer.
So to create it user, let's say let user one is equal to user and this is where that key pair value
comes into play.
So we're going to say active.
True.
So our key is active and our value is true.
User name and we're going to do string from Tyler.
And then for our last one, we're going to say our sign and count, which is our.
T and then our value of zero.
So how can we access any of this information?
Well.
We have what's known as the dot notation.
So let's print out my username.
So we're going to say user one and then dot.
And then now you can see that these attributes appear.
So again, I wanted to print out my username.
And this dot notation is how we can access the attributes inside of our.
So now if we run it, I expect it to say Tyler, which is exactly what happened.
All right.
So good.
So something else that we can do is we can create.
A function that's going to build our user for us.
So in here we just want to pass in my username and we want it to be a string and then we want a user
to be returned.
So in here we're going to return a user and we're going to just leave username.
And then we're going to have active as true.
And then we're going to auto assign our sign and count to one.
So what's happening here?
So how come we don't have to assign anything to username?
Well, it's smart enough to realize, hey, we have a username parameter and a username attribute.
So it's automatically going to map those two together.
So we don't have to have any logic down here to basically say, hey, username is user name because
that's the same thing it's doing.
But Russ is smart enough to do that and make that correlation for us, and then we're just going to
go ahead and preset in these values for every user that we do this way.
So let's go ahead and build a user.
So we're going to say let user two is equal to build user.
And then in here we're going to say we want the name to be string from
and we'll do Tyler two.
And then let's just go ahead and print out our username again to make sure that that that worked the
way that we were intending.
And that's exactly what we got.
So we got Tyler, too.
So.
Now what are the tuple like structs that we talked about?
So remember to pull structs, identify the values by the order in which they appear.
So if we come up here and we go struct and capital coordinates.
Then we can do I 32, high 32 and then I 32.
So now we can come down here.
And say.
Get rid of that.
There we go.
All right.
So now we can say let Cordes equal coordinates 1 to 3.
So it was able.
To say, okay, we have an I 30 to another I 32 and another I 32 and that's all there is to it for the
tuple structs.
So remember tuple like structs identify the values by the order in which they appear.
But now what about a unit like stroke?
So a unit like stroke can be done like this.
So now we have a unit like struck.
What's the use of this?
Well, we've actually already have used a unit struck prior in this course when we did the one.
To five.
Collect method when we were for like a range when we were populating a vector, the dot dot is shorthand
for the struct value range.
So it's range and it is set up from like start one and then end five.
So we will be able to see how these unit like structures are a little bit more useful when we start
to talk about traits a little later on in this course.
But for now, the main structure we're going to be using are the named field ones.
So what we need to do now is start looking at how we can implement methods on these structs.