1 00:00:06,540 --> 00:00:07,680 - So far in this lesson, 2 00:00:07,680 --> 00:00:09,420 we've seen how to declare variables. 3 00:00:09,420 --> 00:00:12,690 We've seen integers, floats, characters, and Booleans. 4 00:00:12,690 --> 00:00:13,740 And to wrap up the lesson, 5 00:00:13,740 --> 00:00:16,650 we're going to look at some additional techniques 6 00:00:16,650 --> 00:00:17,850 to help you write your code 7 00:00:17,850 --> 00:00:19,530 more like a Rust developer would. 8 00:00:19,530 --> 00:00:22,110 So some additional techniques which are quite useful, 9 00:00:22,110 --> 00:00:23,310 some of them are a bit surprising, 10 00:00:23,310 --> 00:00:24,360 but all of 'em interesting. 11 00:00:24,360 --> 00:00:28,770 So first of all, we have this concept of inferred types. 12 00:00:28,770 --> 00:00:32,040 When you declare a variable, if you give it a value, 13 00:00:32,040 --> 00:00:34,410 then you don't also need to specify the type. 14 00:00:34,410 --> 00:00:36,060 The compiler can guess the type 15 00:00:36,060 --> 00:00:37,980 based on the value that you provide. 16 00:00:37,980 --> 00:00:40,350 And this is the way that most Rust developers would do it. 17 00:00:40,350 --> 00:00:43,500 So here you can see I've declared A, B, and C. 18 00:00:43,500 --> 00:00:45,510 The compiler, I've given each one a value 19 00:00:45,510 --> 00:00:46,786 and the compiler can guess the types 20 00:00:46,786 --> 00:00:48,450 without me having to specify. 21 00:00:48,450 --> 00:00:52,200 It'll guess that a is an i32, I think, 22 00:00:52,200 --> 00:00:55,080 and it'll guess that b is a F64. 23 00:00:55,080 --> 00:00:56,460 I think that's what it would be. 24 00:00:56,460 --> 00:00:58,350 And C will be a character. 25 00:00:58,350 --> 00:01:02,670 So I don't actually need to say let a colon i32. 26 00:01:02,670 --> 00:01:04,140 I can just give it the value 27 00:01:04,140 --> 00:01:06,362 and it can deduce the type from that value. 28 00:01:06,362 --> 00:01:10,059 This is the way that most Rust developers write their code. 29 00:01:10,059 --> 00:01:14,820 You can also declare variables to be mutable or unmutable. 30 00:01:14,820 --> 00:01:16,950 Surprisingly, if you're coming from a C background 31 00:01:16,950 --> 00:01:20,190 or C Plus Plus or Java, in Rust, 32 00:01:20,190 --> 00:01:22,470 when you declare a variable like I've done here, 33 00:01:22,470 --> 00:01:24,960 by default it's immutable, okay, 34 00:01:24,960 --> 00:01:26,730 which means you can't change it. 35 00:01:26,730 --> 00:01:28,336 There's been a drift in languages 36 00:01:28,336 --> 00:01:30,960 in recent years towards this concept. 37 00:01:30,960 --> 00:01:34,560 Immutable variables are safer than ones that can change. 38 00:01:34,560 --> 00:01:37,680 If you know that a value is immutable, then for example 39 00:01:37,680 --> 00:01:40,680 in a multi-threaded application, you don't need to lock it. 40 00:01:40,680 --> 00:01:42,150 You can't change the value. 41 00:01:42,150 --> 00:01:44,460 So you don't need to lock it when you are accessing it 42 00:01:44,460 --> 00:01:45,864 because it's fixed. 43 00:01:45,864 --> 00:01:50,790 So Rust is really about safety and code integrity. 44 00:01:50,790 --> 00:01:52,770 That's the main selling point for Rust. 45 00:01:52,770 --> 00:01:54,465 So when you declare a variable, 46 00:01:54,465 --> 00:01:57,120 then it is by default immutable. 47 00:01:57,120 --> 00:01:58,260 You can't change the value. 48 00:01:58,260 --> 00:02:00,510 Once you've assigned it. That's it. 49 00:02:00,510 --> 00:02:03,120 If you do want to have a variable that's mutable 50 00:02:03,120 --> 00:02:04,710 then you have to use the mut keyword. 51 00:02:04,710 --> 00:02:07,140 Looks a bit odd, but you do get used to it. 52 00:02:07,140 --> 00:02:10,620 I declared e as a mutable integer. 53 00:02:10,620 --> 00:02:12,510 I've given that initial value of zero, 54 00:02:12,510 --> 00:02:14,730 but then I could change value later on okay? 55 00:02:14,730 --> 00:02:17,622 So you have to explicitly request mutability 56 00:02:17,622 --> 00:02:19,020 if you want it. 57 00:02:19,020 --> 00:02:21,241 If you don't say mut, then it's immutable 58 00:02:21,241 --> 00:02:23,013 by default for safety. 59 00:02:24,256 --> 00:02:26,670 Here's another curiosity. 60 00:02:26,670 --> 00:02:28,320 If you're writing some code, 61 00:02:28,320 --> 00:02:30,180 and you've declared a variable, 62 00:02:30,180 --> 00:02:32,730 but you haven't yet used it, you would normally 63 00:02:32,730 --> 00:02:34,650 get a compiler warning to say 64 00:02:34,650 --> 00:02:36,489 there's an unused variable here. 65 00:02:36,489 --> 00:02:38,973 Did you forget to write some code to use it? 66 00:02:39,840 --> 00:02:42,840 If it's intentional that you haven't yet written the code 67 00:02:42,840 --> 00:02:45,360 but you will, then you can prefix the variable name 68 00:02:45,360 --> 00:02:47,070 with an underscore, okay? 69 00:02:47,070 --> 00:02:49,440 And any variable that starts with an underscore, 70 00:02:49,440 --> 00:02:51,244 you won't get a warning from the compiler 71 00:02:51,244 --> 00:02:53,910 about unused variables okay? 72 00:02:53,910 --> 00:02:54,948 So there we go. 73 00:02:54,948 --> 00:02:56,880 That stops you getting lots of warnings 74 00:02:56,880 --> 00:02:58,110 about unused variables. 75 00:02:58,110 --> 00:03:00,927 Just prefix the name with an underscore. 76 00:03:00,927 --> 00:03:03,185 Okay that's quite straightforward enough. 77 00:03:03,185 --> 00:03:05,760 Now there's the as keyword. 78 00:03:05,760 --> 00:03:08,730 The as keyword is a type conversion. 79 00:03:08,730 --> 00:03:12,990 Rust doesn't do any type conversions on its own. 80 00:03:12,990 --> 00:03:15,450 If you want to convert an integer to a float 81 00:03:15,450 --> 00:03:16,470 or a float to an integer, 82 00:03:16,470 --> 00:03:18,660 you've gotta do that explicitly 83 00:03:18,660 --> 00:03:22,200 using a type conversion using the as keyword okay? 84 00:03:22,200 --> 00:03:25,921 So here in this example g is a floating point value 85 00:03:25,921 --> 00:03:29,970 and I want to basically take g and convert it into 86 00:03:29,970 --> 00:03:34,261 an i32, convert the value into an i32 87 00:03:34,261 --> 00:03:37,675 and that integer value is then assigned to h. 88 00:03:37,675 --> 00:03:40,410 Okay so you have to use the as keyword to do 89 00:03:40,410 --> 00:03:42,300 any type conversions in Rust. 90 00:03:42,300 --> 00:03:44,640 It doesn't do any type conversions unless 91 00:03:44,640 --> 00:03:46,500 you say using the as keyword. 92 00:03:46,500 --> 00:03:50,760 And again, it's for code predictability and code safety. 93 00:03:50,760 --> 00:03:54,453 It only converts when you tell it to using the as keyword. 94 00:03:55,740 --> 00:03:58,350 Now this next one's a bit of a curiosity. 95 00:03:58,350 --> 00:04:03,000 Imagine you ask the user to enter a string, a number, 96 00:04:03,000 --> 00:04:04,680 let's say from the keyboard. 97 00:04:04,680 --> 00:04:06,960 They type in a number 1, 2, 3, 4, 5. 98 00:04:06,960 --> 00:04:09,880 It comes into your application as a string. 99 00:04:09,880 --> 00:04:12,506 You wanna convert it to an integer. 100 00:04:12,506 --> 00:04:16,397 So you might do, there's an pauseint function 101 00:04:16,397 --> 00:04:19,533 that we'll talk about later on in the course, 102 00:04:20,760 --> 00:04:23,460 but you can actually use the same variable name. 103 00:04:23,460 --> 00:04:27,090 So in this example initially I've got a variable called num, 104 00:04:27,090 --> 00:04:28,770 which is a string, 105 00:04:28,770 --> 00:04:31,290 and then maybe I convert it into a number 106 00:04:31,290 --> 00:04:32,790 but then I reassign it back 107 00:04:32,790 --> 00:04:34,260 to a variable with the same name. 108 00:04:34,260 --> 00:04:36,390 I've re-declared the num variable. 109 00:04:36,390 --> 00:04:39,150 It was a string initially, 110 00:04:39,150 --> 00:04:41,968 but from this point onwards, it'll be an integer. 111 00:04:41,968 --> 00:04:44,160 All right, so that's quite surprising. 112 00:04:44,160 --> 00:04:45,090 I think for most people, 113 00:04:45,090 --> 00:04:48,480 the fact that you can reuse a variable name, 114 00:04:48,480 --> 00:04:50,820 because in most other languages you couldn't. 115 00:04:50,820 --> 00:04:52,284 For example, in Java, 116 00:04:52,284 --> 00:04:55,530 if you declared the first variable as a string, 117 00:04:55,530 --> 00:04:59,017 you might declare a variable called num as a str, 118 00:04:59,880 --> 00:05:04,880 and give it a string value, 1, 2, 3, 4, 5, like that. 119 00:05:05,880 --> 00:05:08,850 And then you do some code to convert it to an integer. 120 00:05:08,850 --> 00:05:11,570 And then the integer value, you would then have to assign 121 00:05:11,570 --> 00:05:13,844 in other languages to a variable 122 00:05:13,844 --> 00:05:18,183 with a different name like num int. 123 00:05:19,260 --> 00:05:22,290 Okay, so initially you invented this name for the variable 124 00:05:22,290 --> 00:05:25,290 and then you invented this name for the second variable. 125 00:05:25,290 --> 00:05:28,740 And what Rust says is, or what you can say in Rust is 126 00:05:28,740 --> 00:05:30,930 you know, really it's the same concept. 127 00:05:30,930 --> 00:05:34,769 Initially, I'm going to express the number in string format 128 00:05:34,769 --> 00:05:39,330 but from here onwards, I want to express it as an integer. 129 00:05:39,330 --> 00:05:42,720 So from here onwards, it'll use the num as an integer. 130 00:05:42,720 --> 00:05:44,700 You don't have to invent different names for it. 131 00:05:44,700 --> 00:05:48,390 You can recycle the name and then use the new variable, 132 00:05:48,390 --> 00:05:51,120 the integer variable here afterwards, okay? 133 00:05:51,120 --> 00:05:53,520 You can still use it, the kind of old style approach 134 00:05:53,520 --> 00:05:55,560 if you like giving it variable names, 135 00:05:55,560 --> 00:05:57,060 which are kind of different 136 00:05:57,060 --> 00:05:58,650 or you can use the same variable name 137 00:05:58,650 --> 00:06:01,353 if you prefer as supported in Rust. 138 00:06:03,330 --> 00:06:06,900 Right one final thing, I'm gonna show you a demo after this. 139 00:06:06,900 --> 00:06:09,270 You can have compile-time constants. 140 00:06:09,270 --> 00:06:11,640 A value which is known at compile time 141 00:06:11,640 --> 00:06:13,950 doesn't need to be evaluated at runtime. 142 00:06:13,950 --> 00:06:16,740 So therefore slightly more efficient, 143 00:06:16,740 --> 00:06:19,080 because there's no runtime code involved. 144 00:06:19,080 --> 00:06:21,220 In this example, use the const keyword. 145 00:06:21,220 --> 00:06:23,856 Rust is quite fussy. 146 00:06:23,856 --> 00:06:25,920 When you have a const keyword, you basically 147 00:06:25,920 --> 00:06:28,770 have to use capital letters for the variable name. 148 00:06:28,770 --> 00:06:31,050 It's quite fussy about names. 149 00:06:31,050 --> 00:06:33,096 And you've also gotta specify 150 00:06:33,096 --> 00:06:35,790 the type of the variable as well. 151 00:06:35,790 --> 00:06:38,670 Okay you could argue that it can guess 152 00:06:38,670 --> 00:06:41,310 it can see that seconds in hour 153 00:06:41,310 --> 00:06:43,691 I've given it the value 3,600. 154 00:06:43,691 --> 00:06:46,078 It can see that it's an i32, 155 00:06:46,078 --> 00:06:49,410 but you have to explicitly tell it. 156 00:06:49,410 --> 00:06:51,930 Again, I think it's just for predictable code, 157 00:06:51,930 --> 00:06:54,600 so that it doesn't get the wrong idea. 158 00:06:54,600 --> 00:06:57,502 Okay and by the way the underscore here 159 00:06:57,502 --> 00:07:00,000 doesn't have any kind of real meaning. 160 00:07:00,000 --> 00:07:02,513 It's just there as a developer nicety 161 00:07:02,513 --> 00:07:07,440 to make it clearer, easier how to read the number 3,600. 162 00:07:07,440 --> 00:07:09,420 The underscore doesn't actually have any real meaning. 163 00:07:09,420 --> 00:07:12,806 It's just there for us programmers to read more easily. 164 00:07:12,806 --> 00:07:15,000 Let's have a look at an example. 165 00:07:15,000 --> 00:07:18,112 Same project as before, lesson two variables types. 166 00:07:18,112 --> 00:07:21,180 And it's the demo additional type function 167 00:07:21,180 --> 00:07:22,140 we're gonna look at. 168 00:07:22,140 --> 00:07:24,543 Then we'll run the example as usual. 169 00:07:25,380 --> 00:07:29,280 Okay, so here's my code, and in the main function 170 00:07:29,280 --> 00:07:33,630 I'm going to uncomment a call to that function. 171 00:07:33,630 --> 00:07:35,670 And here is the function down here. 172 00:07:35,670 --> 00:07:37,890 It's basically got bits of code similar 173 00:07:37,890 --> 00:07:39,920 to what we looked at in the slide, okay? 174 00:07:39,920 --> 00:07:43,170 So I'm gonna run through that in a moment. 175 00:07:43,170 --> 00:07:46,353 I'll run it first of all, so we can actually see the output. 176 00:07:47,280 --> 00:07:48,290 I think it'd be beneficial to be able 177 00:07:48,290 --> 00:07:49,410 to see the output first, 178 00:07:49,410 --> 00:07:51,443 and then we can kind of go through the code 179 00:07:51,443 --> 00:07:54,243 as we're discussing, cargo run. 180 00:07:55,698 --> 00:07:58,710 So it gave me a few warnings about unused functions, 181 00:07:58,710 --> 00:08:01,380 same as before and ignore those. 182 00:08:01,380 --> 00:08:05,220 And then we declared some variables of inferred type. 183 00:08:05,220 --> 00:08:08,190 So an integer, a float, and a character. 184 00:08:08,190 --> 00:08:10,410 I've got some new line characters 185 00:08:10,410 --> 00:08:11,460 being displayed as well here 186 00:08:11,460 --> 00:08:13,830 just to make my output look nice. 187 00:08:13,830 --> 00:08:16,320 So it outputs the value of A, B, and C. 188 00:08:16,320 --> 00:08:17,670 No great surprises there. 189 00:08:17,670 --> 00:08:21,000 Those are the values of A, B, and C as expected. 190 00:08:21,000 --> 00:08:22,800 And then here I've got a variable, 191 00:08:22,800 --> 00:08:25,200 which is immutable by default. 192 00:08:25,200 --> 00:08:29,310 If I try to change it, I'm gonna get a compiler error. 193 00:08:29,310 --> 00:08:31,918 Now, if I try to run the application, 194 00:08:31,918 --> 00:08:35,313 line 80 is gonna gimme an error. 195 00:08:36,600 --> 00:08:38,520 The warnings or the errors that you get in Rust 196 00:08:38,520 --> 00:08:40,050 are actually quite useful. 197 00:08:40,050 --> 00:08:45,050 It'll tell you there's an error on line 80, count the five. 198 00:08:46,590 --> 00:08:49,800 So here we are, here's line 80, 199 00:08:49,800 --> 00:08:51,810 but it tells you why the error occurred. 200 00:08:51,810 --> 00:08:54,862 It says, well, in the beginning you declared the variable 201 00:08:54,862 --> 00:08:56,610 and it wasn't mutable. 202 00:08:56,610 --> 00:08:57,540 Maybe it should have been 203 00:08:57,540 --> 00:09:00,123 because then you tried to reassign it, the value. 204 00:09:01,080 --> 00:09:05,070 Okay so it'll tell you what caused the error in blue, 205 00:09:05,070 --> 00:09:07,470 and then it tells you what the error actually is in red. 206 00:09:07,470 --> 00:09:08,910 So that's actually really useful. 207 00:09:08,910 --> 00:09:11,550 It tells you how to fix the error as well. 208 00:09:11,550 --> 00:09:15,030 The wording of the error message is quite useful. 209 00:09:15,030 --> 00:09:20,030 Quite suggestive, cannot assign twice to immutable variable. 210 00:09:20,225 --> 00:09:23,610 So when you declare an immutable variable, 211 00:09:23,610 --> 00:09:26,760 you don't have to initialize it all at once. 212 00:09:26,760 --> 00:09:29,130 You can declare it on one statement 213 00:09:29,130 --> 00:09:31,890 and then assign the value on the next statement. 214 00:09:31,890 --> 00:09:34,800 So that actually is okay. 215 00:09:34,800 --> 00:09:36,720 It's just that you can't assign it the value twice. 216 00:09:36,720 --> 00:09:40,443 So as it stands now, if I rebuild and rerun it, 217 00:09:42,180 --> 00:09:45,360 it'll actually be okay, I'm not gonna get any errors now. 218 00:09:45,360 --> 00:09:47,670 I declared it as immutable. 219 00:09:47,670 --> 00:09:50,670 You are allowed to assign it the value once somewhere, 220 00:09:50,670 --> 00:09:52,704 not necessarily immediately, 221 00:09:52,704 --> 00:09:55,800 but you're not allowed to then reassign it the value again. 222 00:09:55,800 --> 00:09:58,050 So if I then try to do this, okay, 223 00:09:58,050 --> 00:10:01,500 then the first assignment would be, okay, 224 00:10:01,500 --> 00:10:03,000 it's gotta have some value. 225 00:10:03,000 --> 00:10:05,160 The second assignment is the problem. 226 00:10:05,160 --> 00:10:07,143 So now I'm gonna get an error again. 227 00:10:09,390 --> 00:10:12,000 Okay, so we're kind of back to square one. 228 00:10:12,000 --> 00:10:15,063 So let me just revert my code to as it was, 229 00:10:16,020 --> 00:10:19,470 and I'll just kind of get rid of that statement. 230 00:10:19,470 --> 00:10:22,350 If you want to have a variable that is mutable, 231 00:10:22,350 --> 00:10:25,530 then you've gotta explicitly say mutable like so. 232 00:10:25,530 --> 00:10:28,650 Okay, so originally e will be zero. 233 00:10:28,650 --> 00:10:31,650 Afterwards, e will be one. 234 00:10:31,650 --> 00:10:35,310 Let's just verify what could possibly go wrong. 235 00:10:35,310 --> 00:10:37,023 Cargo run. 236 00:10:39,270 --> 00:10:44,220 Okay, so e was originally zero and afterwards e is one. 237 00:10:44,220 --> 00:10:46,083 Excellent what you might be tempted to do 238 00:10:46,083 --> 00:10:48,450 if you are familiar with C Plus Plus 239 00:10:48,450 --> 00:10:49,890 or almost any other language 240 00:10:49,890 --> 00:10:51,750 you might be tempted to say use the plus plus 241 00:10:51,750 --> 00:10:56,430 operator either as a postfix or as a prefix. 242 00:10:56,430 --> 00:10:58,950 Rust doesn't have a plus plus operator. 243 00:10:58,950 --> 00:11:01,117 It doesn't have a minus minus operator either. 244 00:11:01,117 --> 00:11:04,773 So I'm gonna get an error when I try to build and run. 245 00:11:05,750 --> 00:11:08,130 Plus plus is not a valid operator. 246 00:11:08,130 --> 00:11:09,930 It says prefix here. 247 00:11:09,930 --> 00:11:13,350 It's not valid as a postfix operator either. 248 00:11:13,350 --> 00:11:16,500 It suggests using the plus equals instead. 249 00:11:16,500 --> 00:11:17,640 That's quite helpful. 250 00:11:17,640 --> 00:11:20,520 So you could, if you wanted an increment by one, 251 00:11:20,520 --> 00:11:22,556 you could say e plus equals one, 252 00:11:22,556 --> 00:11:25,145 or you could obviously plus equals two, 253 00:11:25,145 --> 00:11:27,630 or you could multiply equals two. 254 00:11:27,630 --> 00:11:28,463 That would be the same 255 00:11:28,463 --> 00:11:31,830 as saying e equals e multiplied by two okay? 256 00:11:31,830 --> 00:11:32,790 So whatever you wanna do 257 00:11:32,790 --> 00:11:34,890 you can rotate it as much as you want now. 258 00:11:35,753 --> 00:11:38,430 Here I've got a variable f, 259 00:11:38,430 --> 00:11:42,180 which I might use later on, but I haven't used yet. 260 00:11:42,180 --> 00:11:45,330 The underscore will stop the compiler 261 00:11:45,330 --> 00:11:46,680 from giving me a warning. 262 00:11:46,680 --> 00:11:48,540 If I got rid of the underscore, 263 00:11:48,540 --> 00:11:51,363 I'd get a compiler warning and use local variable. 264 00:11:53,100 --> 00:11:54,540 Okay, and what else? 265 00:11:54,540 --> 00:11:58,950 Conversions. So g was 3.99. 266 00:11:58,950 --> 00:12:02,466 I convert the value 3.99 into an integer 267 00:12:02,466 --> 00:12:04,650 and then I output the value of h. 268 00:12:04,650 --> 00:12:07,440 So let's see, what is the value of g 269 00:12:07,440 --> 00:12:08,730 and what is the value of h? 270 00:12:08,730 --> 00:12:10,113 Let's give that a spin. 271 00:12:11,850 --> 00:12:16,020 So g is 3.99 and h is three. 272 00:12:16,020 --> 00:12:18,240 And again I think that's probably what you'd expect, 273 00:12:18,240 --> 00:12:20,670 isn't it when you take a fluid point number 274 00:12:20,670 --> 00:12:21,720 and convert it to an end. 275 00:12:21,720 --> 00:12:25,110 It doesn't round up, it just truncates, okay? 276 00:12:25,110 --> 00:12:27,720 It kind of goes downwards towards negative infinity. 277 00:12:27,720 --> 00:12:31,920 So 3.99 becomes three when you convert it into an integer 278 00:12:31,920 --> 00:12:33,960 as you can see down here. 279 00:12:33,960 --> 00:12:38,700 And then, so here's my num as a string. 280 00:12:38,700 --> 00:12:41,339 Okay, so num as a string is there, 281 00:12:41,339 --> 00:12:44,580 and then I've repurposed the num keyword. 282 00:12:44,580 --> 00:12:46,980 So that num is now an integer okay? 283 00:12:46,980 --> 00:12:48,660 So now I can do maths on it. 284 00:12:48,660 --> 00:12:50,247 Okay, now it's an integer. 285 00:12:50,247 --> 00:12:54,030 I can now treat it as an integer and I can do maths on it. 286 00:12:54,030 --> 00:12:54,933 I can add one. 287 00:12:55,980 --> 00:12:58,673 And then finally I've got a const, 288 00:12:59,940 --> 00:13:01,830 the number of seconds in an hour. 289 00:13:01,830 --> 00:13:05,361 you have to tell it as an integer 3,600. 290 00:13:05,361 --> 00:13:07,200 That's a compiled time constant. 291 00:13:07,200 --> 00:13:09,930 So is this, this is a compile time constant, 292 00:13:09,930 --> 00:13:12,360 even though I've done a bit of maths, 293 00:13:12,360 --> 00:13:14,940 it's all completely doable at compile time. 294 00:13:14,940 --> 00:13:17,847 So the compiler will effectively do the multiplication, 295 00:13:17,847 --> 00:13:21,288 and it'll tell me that the number of seconds in a day, 296 00:13:21,288 --> 00:13:24,300 if there are that many seconds in an hour, 297 00:13:24,300 --> 00:13:27,750 and there are 24 hours in a day, then the number 298 00:13:27,750 --> 00:13:32,400 of seconds in a day will be that number there okay? 299 00:13:32,400 --> 00:13:34,920 So the techniques that I've shown you 300 00:13:34,920 --> 00:13:39,030 in this section here are important. 301 00:13:39,030 --> 00:13:42,164 Rust developers tend to use type inference. 302 00:13:42,164 --> 00:13:46,140 Rust developers tend to declare variables as immutable 303 00:13:46,140 --> 00:13:47,670 wherever they can, 304 00:13:47,670 --> 00:13:50,280 and they only declare mutable where they have to. 305 00:13:50,280 --> 00:13:53,233 And you have to make an effort like that. 306 00:13:53,233 --> 00:13:55,830 Using underscores to avoid warnings. 307 00:13:55,830 --> 00:13:57,660 Most organizations have a rule 308 00:13:57,660 --> 00:14:00,840 that you're not allowed to run code that has warnings. 309 00:14:00,840 --> 00:14:03,270 So this would get rid of warnings. 310 00:14:03,270 --> 00:14:04,290 Type conversions. 311 00:14:04,290 --> 00:14:06,030 You do when you have to. 312 00:14:06,030 --> 00:14:08,250 It always feels a little bit unclean, 313 00:14:08,250 --> 00:14:09,720 but sometimes you do have to convert 314 00:14:09,720 --> 00:14:12,243 from one type to another using the as keyword. 315 00:14:13,350 --> 00:14:14,970 And then recycling variable names. 316 00:14:14,970 --> 00:14:16,440 You don't tend to do that much, 317 00:14:16,440 --> 00:14:18,780 but it's useful when you need to use it. 318 00:14:18,780 --> 00:14:20,358 And then compile time constants, 319 00:14:20,358 --> 00:14:24,060 obviously they give you readability. 320 00:14:24,060 --> 00:14:27,300 It's much better to have a compile time constant 321 00:14:27,300 --> 00:14:31,410 to represent a number like here, seconds in day. 322 00:14:31,410 --> 00:14:33,697 I could have hard coded that as being 86,400. 323 00:14:37,620 --> 00:14:39,090 But anybody reading my code will think 324 00:14:39,090 --> 00:14:41,100 what on earth is that number? 325 00:14:41,100 --> 00:14:42,900 Is that your daily salary? 326 00:14:42,900 --> 00:14:44,010 Sadly not. 327 00:14:44,010 --> 00:14:46,260 It's the number of seconds in a day, 328 00:14:46,260 --> 00:14:48,090 but using the name of the variable 329 00:14:48,090 --> 00:14:51,090 or the name of the constant makes my code clearer. 330 00:14:51,090 --> 00:14:53,280 Okay, so that wraps up this lesson. 331 00:14:53,280 --> 00:14:54,113 Good to go.