1 00:00:05,730 --> 00:00:10,110 And this lecture we're going to talk about variables and mutability. 2 00:00:11,160 --> 00:00:18,270 Variables are how we are going to store the data that is necessary for our application to run. 3 00:00:18,270 --> 00:00:21,390 And then mutability is going to refer to how. 4 00:00:23,070 --> 00:00:25,110 That data can be manipulated. 5 00:00:25,650 --> 00:00:33,060 If it's mutable, we are able to modify the variable, but if it's in mutable, we will not be allowed 6 00:00:33,060 --> 00:00:34,020 to modify it. 7 00:00:34,170 --> 00:00:42,390 So to demonstrate this, we're going to create a new directory called Variables Using Cargo, and we're 8 00:00:42,390 --> 00:00:44,100 going to change into that directory. 9 00:00:44,640 --> 00:00:47,430 So now if we look at the folder structure. 10 00:00:48,990 --> 00:00:51,690 It is the same as what we're used to, especially with Helo. 11 00:00:51,690 --> 00:00:56,430 So we'll go into main hours and we will delete. 12 00:00:57,800 --> 00:00:58,490 That line. 13 00:00:58,880 --> 00:01:02,360 So the first thing that we're going to do is use the keyword. 14 00:01:02,360 --> 00:01:05,210 And this is basically saying, hey, this is going to be a variable. 15 00:01:05,210 --> 00:01:14,480 So we're going to say let X equal five and then we're going to use the print line macro, which is going 16 00:01:14,480 --> 00:01:18,050 to allow us to print information out to the terminal. 17 00:01:18,350 --> 00:01:21,440 We'll cover macros more in depth later on. 18 00:01:21,440 --> 00:01:26,780 But for now, just know that print line with the exclamation point is how you print information out 19 00:01:26,780 --> 00:01:28,610 to the terminal. 20 00:01:28,850 --> 00:01:30,110 So we will say. 21 00:01:31,360 --> 00:01:36,070 The value of x is and then curly brackets. 22 00:01:38,800 --> 00:01:41,320 And specify the variable that we want to print out. 23 00:01:43,450 --> 00:01:47,650 Also if you're not super familiar with Visual Studio code. 24 00:01:48,640 --> 00:01:54,470 If you click file and go down to AutoSave, it'll automatically save for you. 25 00:01:54,490 --> 00:01:56,830 That way, you don't have to continuously do it. 26 00:01:58,340 --> 00:02:05,530 Now, if we run cargo build and cargo run, we get the desired output of the value of x is five. 27 00:02:05,800 --> 00:02:09,340 So now what happens if we try to assign? 28 00:02:11,070 --> 00:02:15,930 Six to the variable x and then print out the same. 29 00:02:19,370 --> 00:02:22,790 So we will build it again and we get an air. 30 00:02:23,360 --> 00:02:24,860 So if we bring this up. 31 00:02:26,280 --> 00:02:32,640 We can see that the air says cannot assign twice to immutable variable x and it'll tell us that. 32 00:02:33,470 --> 00:02:40,670 At line two, we first assigned to X and then at line six we're trying to reassign to X, but it also 33 00:02:40,670 --> 00:02:43,010 says considered making this binding mutable. 34 00:02:43,850 --> 00:02:46,880 So if we come up here and put. 35 00:02:48,270 --> 00:02:48,870 Cute. 36 00:02:50,330 --> 00:02:54,380 X our air for that squiggly that was that line six. 37 00:02:54,380 --> 00:02:58,610 So just so you can see it again how it's how it has it here. 38 00:02:58,610 --> 00:03:01,970 So now if we put mute that air is now gone. 39 00:03:01,970 --> 00:03:09,620 So if we build it again and then run, we now have the desired output. 40 00:03:09,950 --> 00:03:18,740 So what this is keyword right here is doing is it's allowing us to be able to modify the X variable. 41 00:03:19,970 --> 00:03:26,930 So that's really important to know because if you forget that mute keyword, then you're not allowed 42 00:03:26,930 --> 00:03:29,150 to modify any variables. 43 00:03:29,990 --> 00:03:36,800 Another keyword that we can use to make sure variables are not able to be modified is const. 44 00:03:38,510 --> 00:03:43,880 Konst is going to allow the variable to live as long as the program is alive. 45 00:03:44,150 --> 00:03:50,590 So what we'll do is we'll create a count called seconds and we'll assign it the data type of eight. 46 00:03:51,640 --> 00:03:55,810 And I'll get into data types in the next lecture. 47 00:03:56,140 --> 00:03:59,650 Now by Russia's naming convention. 48 00:04:01,160 --> 00:04:04,850 Constants are always going to be in all capital letters. 49 00:04:04,850 --> 00:04:10,280 So any time you see a variable in all caps, it should be a concert by naming convention. 50 00:04:11,180 --> 00:04:14,600 So what we'll do here is we'll print out again. 51 00:04:16,580 --> 00:04:30,140 The value of seconds is seconds and we will cargo build, cargo run and we see the value of seconds 52 00:04:30,140 --> 00:04:31,100 is 60. 53 00:04:31,220 --> 00:04:33,530 So constants cannot. 54 00:04:34,460 --> 00:04:36,890 B mutated at all. 55 00:04:37,610 --> 00:04:40,280 So as you can see, it's already complaining about it. 56 00:04:40,610 --> 00:04:42,470 Cons globals cannot be mutable. 57 00:04:42,470 --> 00:04:50,020 So luckily Russ is really friendly with telling us all of this information, but it's all very important. 58 00:04:50,030 --> 00:04:56,880 Beginner steps on knowing how to instantiate a variable. 59 00:04:56,900 --> 00:05:01,040 So in the next lecture we will talk about data types.