In this lecture, we are going to take a look at arrays.
Storing a list of data is a common type of action you may want to perform.
For example, we can store lists of posts, users purchases, et cetera.
Arrays are commonly used in languages to store a list of data.
Rust supports arrays But there's one caveat the size of an array is fixed.
For example, if the size of an array is five, the array may never contain more than five values.
We can't add new items to the array.
Rust constraints the size of an array after initialization.
Let's give arrays a try at the bottom of our function.
Let's create a variable called items.
An array can be created by adding new pair of square brackets, the square brackets may contain our
collection of values.
Each value is separated by a comma.
For this demonstration, let's add five numbers.
The size of the array is five.
We can hover our mouse to verify the size.
Our editor has annotated the array.
This feature is another thing to be aware of.
The values in the array must be of the same type.
In our example, the types are integers after the type, the size of the array is written.
We have the option of annotating the array after the variable name.
Let's add an annotation arrays can be annotated by adding a pair of square brackets.
The annotation is going to need two pieces of information.
The first piece of information is the data type of the array.
For this example, we are creating an array of integers.
Next, we need to add a semicolon, followed by the size of the array.
This step is optional, but you may need to know how to annotate an array if they comply, and there
are Canton for the array.
Let's try logging the way by using the print line.
Macro arrays can't be printed.
We need to use a placeholder inside the string and a debug placeholder.
For the second to arguments will pass in the array.
Lastly, let's try running B cargo run command.
The array gets neatly formatted in the console.
There's not much else to say about arrays.
An array must have a fixed size, and the values in an array must have the same type in the next lecture.
We will begin looking at another data type for storing a collection of data.