In this lecture, we're going to talk about compound types.
Compound types can be can group multiple values into one type.
And rust has two primitive compound types, tuples and arrays.
So we're going to start with what a tuple is.
A tuple is a general way of grouping together a number of values with a variety of types and to one
compound type tuples have a fixed length.
So once they're declared, they cannot grow or shrink in size.
So let's look at what a tuple is.
So we'll say let two equals parentheses.
And then remember they can be a ton of different values.
So we'll just give them one an integer, one a string, and then one a boolean.
So how can you access?
These information, these data.
Inside the variable too.
So what we can do and we'll just print it out is set up our normal stuff.
And then if you type to period, you see you have 012.
So the way.
Counting works and programming is the first element, which in this case is 500 always starts at zero.
So we'll always go zero, one, two, and it works the same way in arrays and vectors and so on.
So.
The index of this is going to be zero.
So if we typed out zero.
And then we built it and run it.
We see 500.
But the same thing works as if we did one.
And also if we did, too.
So that's how you can access the information inside of a tuple that way.
But say you want it to assign each value inside the tuple to.
A different variable.
So we'll say let X, Y and z equal to.
So now we can inference that X is going to link to 500, y is going to be assigned to high and Z is
going to be assigned to true.
So to test this out, let's print out the values and let's see what happens.
So we have X.
And then we will copy and paste.
Y z.
Clear cargo build.
Cargo run.
And now we see that we have X is 500, Y is high and z is true.
So that is how you can use a tuple to assign.
Multiple values into one type.
And then you can also pull those values out and assign them to different variables.
And the next lecture, we're going to look at a raise, which is another way to have a collection of
multiple values that all have the same type.