1 00:00:05,900 --> 00:00:08,960 In this lecture, we're going to talk about compound types. 2 00:00:09,320 --> 00:00:14,660 Compound types can be can group multiple values into one type. 3 00:00:14,870 --> 00:00:19,460 And rust has two primitive compound types, tuples and arrays. 4 00:00:19,640 --> 00:00:22,730 So we're going to start with what a tuple is. 5 00:00:23,420 --> 00:00:30,290 A tuple is a general way of grouping together a number of values with a variety of types and to one 6 00:00:30,290 --> 00:00:34,070 compound type tuples have a fixed length. 7 00:00:34,070 --> 00:00:38,060 So once they're declared, they cannot grow or shrink in size. 8 00:00:38,060 --> 00:00:40,040 So let's look at what a tuple is. 9 00:00:40,130 --> 00:00:45,230 So we'll say let two equals parentheses. 10 00:00:45,230 --> 00:00:50,510 And then remember they can be a ton of different values. 11 00:00:50,510 --> 00:00:56,240 So we'll just give them one an integer, one a string, and then one a boolean. 12 00:00:58,480 --> 00:01:00,550 So how can you access? 13 00:01:01,800 --> 00:01:04,270 These information, these data. 14 00:01:05,730 --> 00:01:07,260 Inside the variable too. 15 00:01:07,290 --> 00:01:14,280 So what we can do and we'll just print it out is set up our normal stuff. 16 00:01:14,280 --> 00:01:19,470 And then if you type to period, you see you have 012. 17 00:01:19,890 --> 00:01:20,850 So the way. 18 00:01:21,610 --> 00:01:29,620 Counting works and programming is the first element, which in this case is 500 always starts at zero. 19 00:01:30,280 --> 00:01:37,540 So we'll always go zero, one, two, and it works the same way in arrays and vectors and so on. 20 00:01:38,840 --> 00:01:39,530 So. 21 00:01:40,760 --> 00:01:43,610 The index of this is going to be zero. 22 00:01:43,610 --> 00:01:45,620 So if we typed out zero. 23 00:01:47,040 --> 00:01:51,210 And then we built it and run it. 24 00:01:51,540 --> 00:01:52,860 We see 500. 25 00:01:53,070 --> 00:01:55,350 But the same thing works as if we did one. 26 00:01:58,880 --> 00:02:01,490 And also if we did, too. 27 00:02:04,340 --> 00:02:09,170 So that's how you can access the information inside of a tuple that way. 28 00:02:10,100 --> 00:02:16,010 But say you want it to assign each value inside the tuple to. 29 00:02:17,300 --> 00:02:18,380 A different variable. 30 00:02:18,380 --> 00:02:24,940 So we'll say let X, Y and z equal to. 31 00:02:26,240 --> 00:02:33,920 So now we can inference that X is going to link to 500, y is going to be assigned to high and Z is 32 00:02:33,920 --> 00:02:35,360 going to be assigned to true. 33 00:02:35,390 --> 00:02:42,350 So to test this out, let's print out the values and let's see what happens. 34 00:02:42,350 --> 00:02:43,670 So we have X. 35 00:02:44,690 --> 00:02:47,300 And then we will copy and paste. 36 00:02:50,330 --> 00:02:53,630 Y z. 37 00:02:54,470 --> 00:02:57,020 Clear cargo build. 38 00:02:57,770 --> 00:02:58,780 Cargo run. 39 00:02:58,790 --> 00:03:04,160 And now we see that we have X is 500, Y is high and z is true. 40 00:03:04,310 --> 00:03:08,030 So that is how you can use a tuple to assign. 41 00:03:09,290 --> 00:03:11,270 Multiple values into one type. 42 00:03:11,270 --> 00:03:16,040 And then you can also pull those values out and assign them to different variables. 43 00:03:17,050 --> 00:03:22,300 And the next lecture, we're going to look at a raise, which is another way to have a collection of 44 00:03:22,300 --> 00:03:25,810 multiple values that all have the same type.