1
00:00:00,390 --> 00:00:03,810
In this lecture, we are going to take a look at arrays.

2
00:00:04,110 --> 00:00:08,580
Storing a list of data is a common type of action you may want to perform.

3
00:00:08,940 --> 00:00:14,670
For example, we can store lists of posts, users purchases, et cetera.

4
00:00:15,090 --> 00:00:19,140
Arrays are commonly used in languages to store a list of data.

5
00:00:19,500 --> 00:00:25,380
Rust supports arrays But there's one caveat the size of an array is fixed.

6
00:00:25,890 --> 00:00:32,369
For example, if the size of an array is five, the array may never contain more than five values.

7
00:00:32,640 --> 00:00:34,950
We can't add new items to the array.

8
00:00:35,280 --> 00:00:39,330
Rust constraints the size of an array after initialization.

9
00:00:39,660 --> 00:00:43,300
Let's give arrays a try at the bottom of our function.

10
00:00:43,320 --> 00:00:45,990
Let's create a variable called items.

11
00:00:48,620 --> 00:00:54,740
An array can be created by adding new pair of square brackets, the square brackets may contain our

12
00:00:54,740 --> 00:00:56,240
collection of values.

13
00:00:56,600 --> 00:00:59,000
Each value is separated by a comma.

14
00:00:59,360 --> 00:01:02,270
For this demonstration, let's add five numbers.

15
00:01:04,750 --> 00:01:06,940
The size of the array is five.

16
00:01:07,210 --> 00:01:10,060
We can hover our mouse to verify the size.

17
00:01:10,420 --> 00:01:12,820
Our editor has annotated the array.

18
00:01:13,210 --> 00:01:15,790
This feature is another thing to be aware of.

19
00:01:16,180 --> 00:01:19,510
The values in the array must be of the same type.

20
00:01:19,870 --> 00:01:26,140
In our example, the types are integers after the type, the size of the array is written.

21
00:01:26,770 --> 00:01:31,210
We have the option of annotating the array after the variable name.

22
00:01:31,210 --> 00:01:37,240
Let's add an annotation arrays can be annotated by adding a pair of square brackets.

23
00:01:37,570 --> 00:01:41,170
The annotation is going to need two pieces of information.

24
00:01:41,560 --> 00:01:45,070
The first piece of information is the data type of the array.

25
00:01:45,460 --> 00:01:49,240
For this example, we are creating an array of integers.

26
00:01:51,830 --> 00:01:56,180
Next, we need to add a semicolon, followed by the size of the array.

27
00:01:58,780 --> 00:02:04,150
This step is optional, but you may need to know how to annotate an array if they comply, and there

28
00:02:04,150 --> 00:02:05,620
are Canton for the array.

29
00:02:05,980 --> 00:02:09,310
Let's try logging the way by using the print line.

30
00:02:09,310 --> 00:02:11,950
Macro arrays can't be printed.

31
00:02:12,220 --> 00:02:17,230
We need to use a placeholder inside the string and a debug placeholder.

32
00:02:19,730 --> 00:02:22,760
For the second to arguments will pass in the array.

33
00:02:25,250 --> 00:02:28,790
Lastly, let's try running B cargo run command.

34
00:02:31,320 --> 00:02:34,080
The array gets neatly formatted in the console.

35
00:02:34,320 --> 00:02:36,660
There's not much else to say about arrays.

36
00:02:36,930 --> 00:02:44,160
An array must have a fixed size, and the values in an array must have the same type in the next lecture.

37
00:02:44,280 --> 00:02:48,780
We will begin looking at another data type for storing a collection of data.

