And this lecture we're going to talk about variables and mutability.
Variables are how we are going to store the data that is necessary for our application to run.
And then mutability is going to refer to how.
That data can be manipulated.
If it's mutable, we are able to modify the variable, but if it's in mutable, we will not be allowed
to modify it.
So to demonstrate this, we're going to create a new directory called Variables Using Cargo, and we're
going to change into that directory.
So now if we look at the folder structure.
It is the same as what we're used to, especially with Helo.
So we'll go into main hours and we will delete.
That line.
So the first thing that we're going to do is use the keyword.
And this is basically saying, hey, this is going to be a variable.
So we're going to say let X equal five and then we're going to use the print line macro, which is going
to allow us to print information out to the terminal.
We'll cover macros more in depth later on.
But for now, just know that print line with the exclamation point is how you print information out
to the terminal.
So we will say.
The value of x is and then curly brackets.
And specify the variable that we want to print out.
Also if you're not super familiar with Visual Studio code.
If you click file and go down to AutoSave, it'll automatically save for you.
That way, you don't have to continuously do it.
Now, if we run cargo build and cargo run, we get the desired output of the value of x is five.
So now what happens if we try to assign?
Six to the variable x and then print out the same.
So we will build it again and we get an air.
So if we bring this up.
We can see that the air says cannot assign twice to immutable variable x and it'll tell us that.
At line two, we first assigned to X and then at line six we're trying to reassign to X, but it also
says considered making this binding mutable.
So if we come up here and put.
Cute.
X our air for that squiggly that was that line six.
So just so you can see it again how it's how it has it here.
So now if we put mute that air is now gone.
So if we build it again and then run, we now have the desired output.
So what this is keyword right here is doing is it's allowing us to be able to modify the X variable.
So that's really important to know because if you forget that mute keyword, then you're not allowed
to modify any variables.
Another keyword that we can use to make sure variables are not able to be modified is const.
Konst is going to allow the variable to live as long as the program is alive.
So what we'll do is we'll create a count called seconds and we'll assign it the data type of eight.
And I'll get into data types in the next lecture.
Now by Russia's naming convention.
Constants are always going to be in all capital letters.
So any time you see a variable in all caps, it should be a concert by naming convention.
So what we'll do here is we'll print out again.
The value of seconds is seconds and we will cargo build, cargo run and we see the value of seconds
is 60.
So constants cannot.
B mutated at all.
So as you can see, it's already complaining about it.
Cons globals cannot be mutable.
So luckily Russ is really friendly with telling us all of this information, but it's all very important.
Beginner steps on knowing how to instantiate a variable.
So in the next lecture we will talk about data types.