1 00:00:06,696 --> 00:00:07,800 - In the previous section, 2 00:00:07,800 --> 00:00:10,170 we introduced the concept of borrowing, 3 00:00:10,170 --> 00:00:11,790 where you take a reference to an object 4 00:00:11,790 --> 00:00:13,110 and then access a variable 5 00:00:13,110 --> 00:00:15,360 without actually claiming ownership of it. 6 00:00:15,360 --> 00:00:16,500 Now, the Rust compiler 7 00:00:16,500 --> 00:00:18,930 has something called the borrow checker, 8 00:00:18,930 --> 00:00:20,790 which enforces some strict rules 9 00:00:20,790 --> 00:00:22,200 about what you're allowed to do 10 00:00:22,200 --> 00:00:23,760 and what you're not allowed to do 11 00:00:23,760 --> 00:00:25,710 when it comes to borrowing. 12 00:00:25,710 --> 00:00:28,200 The borrow checker is quite frustrating initially. 13 00:00:28,200 --> 00:00:31,230 It'll stop you writing the kind of code that you want. 14 00:00:31,230 --> 00:00:32,460 But the reason it stops you is 15 00:00:32,460 --> 00:00:34,020 because it's potentially dangerous. 16 00:00:34,020 --> 00:00:35,640 It's in your best interests 17 00:00:35,640 --> 00:00:38,250 that it doesn't let you make mistakes. 18 00:00:38,250 --> 00:00:41,220 Okay, so what it boils down to is that the borrow checker 19 00:00:41,220 --> 00:00:43,950 in the compiler will enforce these rules. 20 00:00:43,950 --> 00:00:47,730 You're only allowed to have one single mutable reference. 21 00:00:47,730 --> 00:00:50,490 Once you've borrowed an object mutably, 22 00:00:50,490 --> 00:00:52,253 you can't borrow it again, okay? 23 00:00:52,253 --> 00:00:55,500 You are only allowed to have one single writer. 24 00:00:55,500 --> 00:00:57,570 You can have as many readers as you want. 25 00:00:57,570 --> 00:00:59,820 You can have many immutable borrowers. 26 00:00:59,820 --> 00:01:02,700 When you borrow immutably, you're not changing the object. 27 00:01:02,700 --> 00:01:05,610 So it's safe to have many immutable borrows, 28 00:01:05,610 --> 00:01:08,820 but when you take a mutable borrow, 29 00:01:08,820 --> 00:01:11,040 that's potentially dangerous. 30 00:01:11,040 --> 00:01:12,330 It doesn't let you have more than one 31 00:01:12,330 --> 00:01:14,250 in case they interfered with each other. 32 00:01:14,250 --> 00:01:15,900 So let's take some examples 33 00:01:15,900 --> 00:01:18,150 to see how this works in practice. 34 00:01:18,150 --> 00:01:19,230 First of all, 35 00:01:19,230 --> 00:01:23,280 you can have many immutable references to a value. 36 00:01:23,280 --> 00:01:26,400 Because immutable references can't modify the value, 37 00:01:26,400 --> 00:01:28,230 this is guaranteed to be safe. 38 00:01:28,230 --> 00:01:30,540 They're not going to interfere with each other. 39 00:01:30,540 --> 00:01:32,100 Have a look at this example. 40 00:01:32,100 --> 00:01:33,780 I've got a string. 41 00:01:33,780 --> 00:01:36,000 Yeah, let's see, here's my string s, 42 00:01:36,000 --> 00:01:38,580 and it contains the text, hello. 43 00:01:38,580 --> 00:01:40,324 I've declared r1, r2, 44 00:01:40,324 --> 00:01:42,660 and r3 are immutable borrows. 45 00:01:42,660 --> 00:01:45,810 There's no mut keyword, so they're all immutable. 46 00:01:45,810 --> 00:01:48,570 So r1 is an immutable reference, 47 00:01:48,570 --> 00:01:50,937 r2 is an immutable reference, 48 00:01:50,937 --> 00:01:53,520 and r3 is an immutable reference. 49 00:01:53,520 --> 00:01:56,250 So if I printed out r1, r2, r3, 50 00:01:56,250 --> 00:01:59,940 in each case, it'll print the underline string, hello. 51 00:01:59,940 --> 00:02:02,790 So let's see an example of this before we go any further. 52 00:02:03,630 --> 00:02:08,010 This is my demo project for the lesson, lesson07, borrowing. 53 00:02:08,010 --> 00:02:11,310 In the main file, I'm going to un-comment the demo 54 00:02:11,310 --> 00:02:14,880 for this part of the lesson, demo_borrow_checker, 55 00:02:14,880 --> 00:02:17,520 and let's have a look at that code. 56 00:02:17,520 --> 00:02:19,530 So here I've got three separate functions 57 00:02:19,530 --> 00:02:21,300 to illustrate first of all, the fact 58 00:02:21,300 --> 00:02:24,570 that you can define many immutable references, 59 00:02:24,570 --> 00:02:26,370 and then we're gonna see some restrictions 60 00:02:26,370 --> 00:02:28,110 about what you can't do. 61 00:02:28,110 --> 00:02:31,535 So let's first of all, un-comment the first call, 62 00:02:31,535 --> 00:02:34,800 defining_many_immutable_references we'll call that function. 63 00:02:34,800 --> 00:02:36,210 And these other functions, 64 00:02:36,210 --> 00:02:38,400 I'll just comment those out for now. 65 00:02:38,400 --> 00:02:39,540 Let's have a look. 66 00:02:39,540 --> 00:02:41,550 So this is a simple example. 67 00:02:41,550 --> 00:02:43,830 Here's my string, hello. 68 00:02:43,830 --> 00:02:48,830 r1, r2, r3, concurrent immutable references, 69 00:02:49,560 --> 00:02:51,120 that's fine. 70 00:02:51,120 --> 00:02:53,880 If I print out r1, r2, r3, obviously, 71 00:02:53,880 --> 00:02:55,800 it's gonna print the underlying string, 72 00:02:55,800 --> 00:02:57,450 which is going to be, hello. 73 00:02:57,450 --> 00:03:02,450 Let's just run that to confirm, cargo run. 74 00:03:02,877 --> 00:03:06,510 And it prints r1, r2, r3, and in each case, 75 00:03:06,510 --> 00:03:09,510 it's gonna print the underline string, hello, okay? 76 00:03:09,510 --> 00:03:10,470 So that's actually fine. 77 00:03:10,470 --> 00:03:12,720 You can have as many immutable references 78 00:03:12,720 --> 00:03:16,050 as you want to a variable, okay? 79 00:03:16,050 --> 00:03:18,450 Now let's look at some restrictions. 80 00:03:18,450 --> 00:03:20,850 So first of all, let's see what happens, 81 00:03:20,850 --> 00:03:23,250 imagine that you've defined a mutable reference. 82 00:03:23,250 --> 00:03:26,940 So let's say we've got a string and it's mutable, 83 00:03:26,940 --> 00:03:30,060 so that its value could change potentially. 84 00:03:30,060 --> 00:03:32,760 And let's say I've got a mutable reference, r1, 85 00:03:32,760 --> 00:03:35,460 which could change the underlying string 86 00:03:35,460 --> 00:03:37,320 via the mutable reference. 87 00:03:37,320 --> 00:03:39,870 Basically, to cut a long story short, 88 00:03:39,870 --> 00:03:42,480 once you've declared a mutable reference, 89 00:03:42,480 --> 00:03:44,733 you can't have any other reference at all. 90 00:03:45,840 --> 00:03:48,780 r1 is allowed to modify the underlying value, okay? 91 00:03:48,780 --> 00:03:51,843 So via r1, this value could change. 92 00:03:53,340 --> 00:03:57,690 So given that, you can't define another mutable reference. 93 00:03:57,690 --> 00:04:01,230 You wouldn't be able to define another mutable reference r2. 94 00:04:01,230 --> 00:04:06,230 You're not allowed to have more than one mutable reference. 95 00:04:06,360 --> 00:04:07,320 And the reason for that is 96 00:04:07,320 --> 00:04:10,860 because r2 might modify the underlying value. 97 00:04:10,860 --> 00:04:15,860 Via r2, I might modify the string here, 98 00:04:15,930 --> 00:04:19,026 and that could interfere with what r1 sees. 99 00:04:19,026 --> 00:04:22,110 r1 and r2 might get in each other's way. 100 00:04:22,110 --> 00:04:24,420 They might be making simultaneous updates 101 00:04:24,420 --> 00:04:27,990 to the same string, for example, and that's chaos. 102 00:04:27,990 --> 00:04:29,640 So you can't have more 103 00:04:29,640 --> 00:04:33,450 than one mutable reference like that. 104 00:04:33,450 --> 00:04:35,853 You can't even have an immutable reference, r3. 105 00:04:36,840 --> 00:04:39,810 So imagine r3 was an immutable reference. 106 00:04:39,810 --> 00:04:42,570 It wasn't gonna change the value, okay? 107 00:04:42,570 --> 00:04:43,530 But that's not allowed. 108 00:04:43,530 --> 00:04:46,440 Once you've got a mutable reference, 109 00:04:46,440 --> 00:04:47,273 you're not then allowed 110 00:04:47,273 --> 00:04:49,980 to have an immutable reference either, 111 00:04:49,980 --> 00:04:53,430 because via r1, 112 00:04:53,430 --> 00:04:56,333 I could change the underlying value here, okay? 113 00:04:58,950 --> 00:05:02,610 And that might interfere with what r3 sees. 114 00:05:02,610 --> 00:05:05,460 r3 thought it had an immutable string, 115 00:05:05,460 --> 00:05:07,470 and suddenly the value seems to have changed 116 00:05:07,470 --> 00:05:10,980 under the covers through some other mechanism. 117 00:05:10,980 --> 00:05:12,930 So to summarize, 118 00:05:12,930 --> 00:05:17,250 once you've set up a mutable reference, that's it. 119 00:05:17,250 --> 00:05:19,290 You're not allowed to have a mutable reference, 120 00:05:19,290 --> 00:05:21,783 another one, or an immutable reference, 121 00:05:23,629 --> 00:05:25,620 just one writer at a time. 122 00:05:25,620 --> 00:05:27,810 So that's worth an example as well, I think. 123 00:05:27,810 --> 00:05:29,340 Let's go back into my demo. 124 00:05:29,340 --> 00:05:33,301 And now I'm going to un-comment the second function call, 125 00:05:33,301 --> 00:05:37,740 restrictions_after_defining_mutable_reference. 126 00:05:37,740 --> 00:05:39,630 Right, here it is. 127 00:05:39,630 --> 00:05:44,630 Here's my code, and let me just tidy up here. 128 00:05:46,200 --> 00:05:50,610 So I've got a mutable string, which I change. 129 00:05:50,610 --> 00:05:53,040 I set up a mutable reference. 130 00:05:53,040 --> 00:05:54,720 That's fine, so far so good. 131 00:05:54,720 --> 00:05:56,700 But once you've got a mutable reference, 132 00:05:56,700 --> 00:05:59,070 you can't then have another mutable reference 133 00:05:59,070 --> 00:06:01,470 or an immutable reference. 134 00:06:01,470 --> 00:06:04,800 So if I try to un-comment those statements, 135 00:06:04,800 --> 00:06:08,190 I'm gonna get an error on lines 33 and 34. 136 00:06:08,190 --> 00:06:10,020 Let's just show you. 137 00:06:10,020 --> 00:06:11,283 I'll do a cargo check. 138 00:06:13,110 --> 00:06:15,213 And, right. 139 00:06:16,710 --> 00:06:20,130 So yes, here's the first error. 140 00:06:20,130 --> 00:06:21,330 It says, right, first of all, 141 00:06:21,330 --> 00:06:25,800 because you've borrowed mutably, r1 is a mutable borrow, 142 00:06:25,800 --> 00:06:28,530 then you can't have a second mutable borrow. 143 00:06:28,530 --> 00:06:30,210 It's complaining about this attempt 144 00:06:30,210 --> 00:06:32,073 to have a second mutable borrow. 145 00:06:33,030 --> 00:06:37,290 Also, there's more. 146 00:06:37,290 --> 00:06:40,320 Again, because r1 is a mutable reference, 147 00:06:40,320 --> 00:06:43,770 then you can't have an immutable reference either, okay? 148 00:06:43,770 --> 00:06:45,663 So this statement also fails. 149 00:06:47,040 --> 00:06:50,133 So I'm gonna comment those lines back out again. 150 00:06:51,660 --> 00:06:55,560 What's surprising though is that even this statement fails. 151 00:06:55,560 --> 00:06:57,750 Let me explain what's going on here. 152 00:06:57,750 --> 00:07:00,930 So I have my string and I've changed it a bit. 153 00:07:00,930 --> 00:07:03,210 I've got a mutable reference, okay? 154 00:07:03,210 --> 00:07:05,250 So once you've got a mutable reference, 155 00:07:05,250 --> 00:07:08,280 you can't have any other references at all. 156 00:07:08,280 --> 00:07:10,920 But unfortunately, the way the println macro works, 157 00:07:10,920 --> 00:07:14,850 when you call it, it tries to borrow immutably. 158 00:07:14,850 --> 00:07:18,420 It tries to do an immutable borrow of the string. 159 00:07:18,420 --> 00:07:20,700 Well, we've already seen you can't do that. 160 00:07:20,700 --> 00:07:22,860 If you've borrowed it mutably, 161 00:07:22,860 --> 00:07:26,550 then you can't borrow it immutably afterwards, okay? 162 00:07:26,550 --> 00:07:29,550 So that's also going to give me an error. 163 00:07:29,550 --> 00:07:31,263 Let me show you that error. 164 00:07:32,700 --> 00:07:36,330 So line 37, yes, indeed. 165 00:07:36,330 --> 00:07:37,440 It says, but first of all, 166 00:07:37,440 --> 00:07:40,350 because you borrowed it, the string mutable here, 167 00:07:40,350 --> 00:07:42,450 so somebody is potentially changing it, 168 00:07:42,450 --> 00:07:44,550 then you can't have an immutable borrower here. 169 00:07:44,550 --> 00:07:46,500 So to understand this, you need to know 170 00:07:46,500 --> 00:07:49,500 that println tries to immutably borrow 171 00:07:49,500 --> 00:07:52,050 to use the string, and it can't. 172 00:07:52,050 --> 00:07:54,720 Basically means you can't use the string. 173 00:07:54,720 --> 00:07:56,670 If you want to use the string, you can't. 174 00:07:56,670 --> 00:07:59,190 You've gotta use the reference instead. 175 00:07:59,190 --> 00:08:00,750 You could use the reference 176 00:08:00,750 --> 00:08:03,720 to change the string and to print it. 177 00:08:03,720 --> 00:08:04,980 That would work, okay? 178 00:08:04,980 --> 00:08:07,320 So the string that was originally huey, 179 00:08:07,320 --> 00:08:10,190 and then became huey louie, via the reference, 180 00:08:10,190 --> 00:08:12,420 it now becomes huey louie dewey. 181 00:08:12,420 --> 00:08:13,770 So that would actually work. 182 00:08:13,770 --> 00:08:17,160 If I ran that code now, that would work. 183 00:08:17,160 --> 00:08:19,683 So let's just run it, cargo run. 184 00:08:21,840 --> 00:08:23,140 And it's working fine now. 185 00:08:24,360 --> 00:08:26,400 Okay, so just to summarize, 186 00:08:26,400 --> 00:08:28,740 once you've taken a mutable borrow, 187 00:08:28,740 --> 00:08:30,540 you can't have any other borrowers at all. 188 00:08:30,540 --> 00:08:33,300 It's very tight and quite annoying, actually. 189 00:08:33,300 --> 00:08:36,150 I mean, I've gotta say, when I started learning Rust, 190 00:08:36,150 --> 00:08:39,030 I fought against the borrow checker constantly, 191 00:08:39,030 --> 00:08:40,560 and you're never gonna win. 192 00:08:40,560 --> 00:08:43,230 You just have to be careful and follow the rules. 193 00:08:43,230 --> 00:08:47,160 It'll stop you from doing damage in your code. 194 00:08:47,160 --> 00:08:49,860 Right, well, there's another part of the demo 195 00:08:49,860 --> 00:08:51,150 that we're gonna have to look at, 196 00:08:51,150 --> 00:08:55,590 restrictions after defining an immutable reference. 197 00:08:55,590 --> 00:08:56,423 We've just been looking 198 00:08:56,423 --> 00:09:00,270 at the restrictions after defining a mutable reference. 199 00:09:00,270 --> 00:09:01,530 Now we're going to look 200 00:09:01,530 --> 00:09:05,133 at the restrictions after defining an immutable reference. 201 00:09:06,000 --> 00:09:09,990 So restrictions after defining an immutable reference, 202 00:09:09,990 --> 00:09:10,830 easy for you to say. 203 00:09:10,830 --> 00:09:12,990 So imagine I've got a string, 204 00:09:12,990 --> 00:09:15,570 which kind of looks like this, is probably gonna be, hello. 205 00:09:15,570 --> 00:09:19,470 And I've got an immutable reference, r1, okay? 206 00:09:19,470 --> 00:09:22,743 So r1 isn't going to change the string. 207 00:09:25,500 --> 00:09:27,990 r1 isn't allowed to modify the underlying value. 208 00:09:27,990 --> 00:09:30,540 Obviously, because it's immutable. 209 00:09:30,540 --> 00:09:33,480 You can't define a mutable reference, r2. 210 00:09:33,480 --> 00:09:35,700 I'm assuming that the string itself is mutable. 211 00:09:35,700 --> 00:09:39,210 So in theory, the string could change. 212 00:09:39,210 --> 00:09:42,120 I've already got an immutable reference to it. 213 00:09:42,120 --> 00:09:46,110 I can't define a mutable reference, r2, 214 00:09:46,110 --> 00:09:50,250 because r2 might then change the string, 215 00:09:50,250 --> 00:09:51,960 and that would confuse r1. 216 00:09:51,960 --> 00:09:54,420 r1 thought it was basically constant. 217 00:09:54,420 --> 00:09:56,460 If r2 was allowed to change it, 218 00:09:56,460 --> 00:09:57,840 that would be problematic. 219 00:09:57,840 --> 00:09:59,850 If r2 changed the underlying value 220 00:09:59,850 --> 00:10:02,223 of the string, hello world, 221 00:10:03,480 --> 00:10:06,900 then the value of r1 would also seem to change. 222 00:10:06,900 --> 00:10:09,840 But r1 thought it was immutable. 223 00:10:09,840 --> 00:10:11,970 So you can't do this. 224 00:10:11,970 --> 00:10:14,520 Once you've defined an immutable reference, 225 00:10:14,520 --> 00:10:16,680 you can't then define another mutable reference, 226 00:10:16,680 --> 00:10:19,503 because it could change things unexpectedly. 227 00:10:21,150 --> 00:10:23,783 Okay, so let's see an example of that. 228 00:10:23,783 --> 00:10:27,783 Restrictions_after_defining_immutable_reference. 229 00:10:29,220 --> 00:10:33,000 Okay, so I just tidy up my little area down here. 230 00:10:33,000 --> 00:10:33,990 Let's go. 231 00:10:33,990 --> 00:10:37,890 So first of all, the string itself is mutable, potentially, 232 00:10:37,890 --> 00:10:39,003 so huey louie. 233 00:10:39,960 --> 00:10:43,110 You can have as many immutable borrowers as you want. 234 00:10:43,110 --> 00:10:46,440 Remember, having immutable borrows is fine. 235 00:10:46,440 --> 00:10:49,713 So r1 and r2 are both basically pointing to the same string, 236 00:10:50,760 --> 00:10:54,030 but you can't have an immutable borrow. 237 00:10:54,030 --> 00:10:56,193 So this statement would give me an error. 238 00:10:58,800 --> 00:11:03,330 I do a cargo check, on line 54, where it says, 239 00:11:03,330 --> 00:11:05,400 because you've immutably borrowed, 240 00:11:05,400 --> 00:11:06,570 and therefore you're thinking of it 241 00:11:06,570 --> 00:11:09,060 as being like a constant string effectively, 242 00:11:09,060 --> 00:11:11,100 you can't then have a mutable borrow, 243 00:11:11,100 --> 00:11:13,170 because that would change the string. 244 00:11:13,170 --> 00:11:15,690 The string that we thought was gonna be unchangeable 245 00:11:15,690 --> 00:11:19,890 could be changed via r3, okay? 246 00:11:19,890 --> 00:11:24,890 So you can't take a mutable reference to this string, 247 00:11:26,820 --> 00:11:29,853 because it would interfere with your immutable view. 248 00:11:31,170 --> 00:11:33,960 So that statement has to go. 249 00:11:33,960 --> 00:11:38,490 Also, we can't modify the original object either, okay? 250 00:11:38,490 --> 00:11:41,010 Because now that we've basically treating it as immutable, 251 00:11:41,010 --> 00:11:43,230 it's gotta basically not change. 252 00:11:43,230 --> 00:11:45,153 So you can't even do this. 253 00:11:46,170 --> 00:11:49,230 Okay, when you say s.push_str, 254 00:11:49,230 --> 00:11:50,580 what actually happens under the covers? 255 00:11:50,580 --> 00:11:51,810 We'll talk about this later on. 256 00:11:51,810 --> 00:11:53,850 It's kind of like an object oriented concept. 257 00:11:53,850 --> 00:11:57,213 When you call a method on an object, like a string, 258 00:11:58,050 --> 00:12:02,400 what it does effectively is it borrows the string, 259 00:12:02,400 --> 00:12:06,120 it passes a reference to the string as the first parameter. 260 00:12:06,120 --> 00:12:11,120 It's like a this parameter in Java or C++ or C#, 261 00:12:11,970 --> 00:12:14,820 it's actually called a self pointer in Rust. 262 00:12:14,820 --> 00:12:19,080 So when you call a method that's going to modify a string, 263 00:12:19,080 --> 00:12:22,560 what it actually does, to be perfectly honest about it, 264 00:12:22,560 --> 00:12:24,060 is it kind of does that. 265 00:12:24,060 --> 00:12:29,060 The push_str function tries to borrow mutably, 266 00:12:29,430 --> 00:12:31,710 take a mutable reference to the string, 267 00:12:31,710 --> 00:12:33,600 so that it can mutate it, okay? 268 00:12:33,600 --> 00:12:37,680 So this statement here is taking a mutable reference 269 00:12:37,680 --> 00:12:40,350 to the string, and that doesn't work. 270 00:12:40,350 --> 00:12:42,000 Just like this doesn't work. 271 00:12:42,000 --> 00:12:44,970 Once the string has an immutable reference, 272 00:12:44,970 --> 00:12:47,280 it's got to remain fixed. 273 00:12:47,280 --> 00:12:50,250 You can't change it via a mutable reference 274 00:12:50,250 --> 00:12:53,910 and you can't change it via this mutable reference either. 275 00:12:53,910 --> 00:12:57,480 So line 57 is also gonna give an error. 276 00:12:57,480 --> 00:12:58,313 Let's see. 277 00:13:00,330 --> 00:13:03,960 Yes, so a mutable borrow occurs here. 278 00:13:03,960 --> 00:13:04,830 It's quite subtle. 279 00:13:04,830 --> 00:13:08,010 You don't see it, but underneath the surface, 280 00:13:08,010 --> 00:13:09,660 this is effectively what's happening. 281 00:13:09,660 --> 00:13:13,170 It is taking a mutable borrow, and you can't. 282 00:13:13,170 --> 00:13:15,240 Once you have immutable references, 283 00:13:15,240 --> 00:13:17,550 you can't then have mutable references 284 00:13:17,550 --> 00:13:19,533 like this or like that. 285 00:13:20,400 --> 00:13:22,680 So basically it's fixed. 286 00:13:22,680 --> 00:13:24,180 Once you've got an immutable reference, 287 00:13:24,180 --> 00:13:25,590 you can't then change it 288 00:13:25,590 --> 00:13:28,830 whilst that immutable reference is alive. 289 00:13:28,830 --> 00:13:31,350 Whilst this immutable reference is alive, 290 00:13:31,350 --> 00:13:32,850 you can't change the string, 291 00:13:32,850 --> 00:13:34,200 because it would change something 292 00:13:34,200 --> 00:13:36,570 that we thought was immutable. 293 00:13:36,570 --> 00:13:39,660 If these immutable references went out of scope, 294 00:13:39,660 --> 00:13:42,060 then the restrictions are released. 295 00:13:42,060 --> 00:13:44,160 The object is now modifiable 296 00:13:44,160 --> 00:13:45,840 because the immutable references, 297 00:13:45,840 --> 00:13:47,070 so the immutable references 298 00:13:47,070 --> 00:13:50,460 are no longer constraining what we can do. 299 00:13:50,460 --> 00:13:54,780 So anyway, so I've commented out this piece of dodgy code 300 00:13:54,780 --> 00:13:56,670 and I've commented out that as well. 301 00:13:56,670 --> 00:13:59,010 So we're left with immutable references, 302 00:13:59,010 --> 00:14:00,750 which should actually work fine. 303 00:14:00,750 --> 00:14:02,523 Let's just give it one last check. 304 00:14:04,380 --> 00:14:07,050 Cargo run, and it's worked. 305 00:14:07,050 --> 00:14:09,333 So huey and louie, 306 00:14:11,160 --> 00:14:12,993 that's the string. 307 00:14:14,100 --> 00:14:16,397 And when I look at r1 and r2, 308 00:14:17,427 --> 00:14:21,930 r1 is huey louie, and r2 is also huey louie. 309 00:14:21,930 --> 00:14:22,763 There we go. 310 00:14:22,763 --> 00:14:25,260 So the borrower tracker is there for your benefit. 311 00:14:25,260 --> 00:14:26,310 Basically, it means 312 00:14:26,310 --> 00:14:29,910 you can have as many immutable references as you like, 313 00:14:29,910 --> 00:14:31,830 but you can only have one mutable reference 314 00:14:31,830 --> 00:14:32,883 and nothing else.