1 00:00:05,996 --> 00:00:09,008 - So far in this lesson, we've seen how to use arrays 2 00:00:09,008 --> 00:00:12,021 in tuples, both of which are fixed size, 3 00:00:12,021 --> 00:00:15,210 once you've created them, you can't expand them. 4 00:00:15,210 --> 00:00:17,250 If you want to have a resizable collection 5 00:00:17,250 --> 00:00:18,528 then you might want to use vector 6 00:00:18,528 --> 00:00:20,461 or Vec as it's called. 7 00:00:20,461 --> 00:00:23,790 Vec angled bracket T, 8 00:00:23,790 --> 00:00:28,257 it's a generic, sequential, resizable collection. 9 00:00:28,257 --> 00:00:30,270 So it's generic in the sense 10 00:00:30,270 --> 00:00:33,030 that you have to say what type of element it contains, 11 00:00:33,030 --> 00:00:35,790 it'll contain elements of the same type. 12 00:00:35,790 --> 00:00:39,630 It's sequential like an array, starts at element zero 13 00:00:39,630 --> 00:00:42,900 but it is resizable, which is unlike an array. 14 00:00:42,900 --> 00:00:47,550 The Vec structure is defined in the Vec module, 15 00:00:47,550 --> 00:00:50,850 which is part of the standard crate in the standard library. 16 00:00:50,850 --> 00:00:55,530 Okay and this module, std vec is automatically imported 17 00:00:55,530 --> 00:00:57,420 and available in your code, 18 00:00:57,420 --> 00:01:00,210 so you don't need to have any kind of use statement, 19 00:01:00,210 --> 00:01:03,060 you can just use the Vec structure directly 20 00:01:03,060 --> 00:01:04,770 to create vectors. 21 00:01:04,770 --> 00:01:07,800 So there were two different syntaxes to create a vector, 22 00:01:07,800 --> 00:01:10,440 one way or the other the vector needs to know 23 00:01:10,440 --> 00:01:12,540 what type of element it contains. 24 00:01:12,540 --> 00:01:15,060 So when you declare your variable, you can use either 25 00:01:15,060 --> 00:01:17,640 of these syntaxes to give it that information. 26 00:01:17,640 --> 00:01:20,909 In the first example, I declared a mutable vector, V, 27 00:01:20,909 --> 00:01:24,010 and it's of type Vec i32. 28 00:01:24,010 --> 00:01:28,110 Okay, so it will contain 32 bit integers 29 00:01:28,110 --> 00:01:30,360 and then you use this syntax 30 00:01:30,360 --> 00:01:32,670 to actually create the vector itself, 31 00:01:32,670 --> 00:01:35,370 okay, it'll be empty initially, but it'll be resizable. 32 00:01:35,370 --> 00:01:38,910 So technically speaking, Vec is a structure 33 00:01:38,910 --> 00:01:42,426 and it has what we could call a static method. 34 00:01:42,426 --> 00:01:45,360 It creates a vector which is empty initially, 35 00:01:45,360 --> 00:01:48,480 it will eventually contain 32 bit integers. 36 00:01:48,480 --> 00:01:49,860 This is an alternative syntax 37 00:01:49,860 --> 00:01:52,590 which you might prefer or maybe you prefer the first, 38 00:01:52,590 --> 00:01:54,000 you declare the variable 39 00:01:54,000 --> 00:01:56,066 and then you use the type information here, 40 00:01:56,066 --> 00:02:00,180 you say, V is a vector of 32 bit integers, 41 00:02:00,180 --> 00:02:02,280 create a new instance of that type, 42 00:02:02,280 --> 00:02:04,230 and that'll give you back an empty vector 43 00:02:04,230 --> 00:02:05,980 into which you can insert elements. 44 00:02:06,870 --> 00:02:08,880 There is another way of creating a vec, 45 00:02:08,880 --> 00:02:11,490 which people will probably use in practice, 46 00:02:11,490 --> 00:02:13,260 and it looks like this. 47 00:02:13,260 --> 00:02:15,720 There's a macro, a bit like print lin. 48 00:02:15,720 --> 00:02:18,840 There's a macro called Vec exclamation mark, or rather 49 00:02:18,840 --> 00:02:23,490 the macros called Vec and with a lowercase V, notice. 50 00:02:23,490 --> 00:02:27,330 And what this macro does it effectively, it inserts code 51 00:02:27,330 --> 00:02:31,830 to create the vector like this and to insert these elements 52 00:02:31,830 --> 00:02:34,200 into the vector so it creates the vector 53 00:02:34,200 --> 00:02:36,780 and populates it immediately. 54 00:02:36,780 --> 00:02:38,880 And if you declare the vector as multiple, 55 00:02:38,880 --> 00:02:41,460 then you can change it again afterwards if you want to. 56 00:02:41,460 --> 00:02:44,040 Okay. So either of these approaches work. 57 00:02:44,040 --> 00:02:47,460 Create an empty vector if you don't know the data yet 58 00:02:47,460 --> 00:02:50,220 or create a vector and populate it with the data 59 00:02:50,220 --> 00:02:52,170 if you do know what you want to put in. 60 00:02:53,190 --> 00:02:55,710 So to index into a vector, no great surprise, 61 00:02:55,710 --> 00:02:57,630 we use the square brackets. 62 00:02:57,630 --> 00:03:00,960 The index here must be within range. 63 00:03:00,960 --> 00:03:02,410 It does do bounce check-in 64 00:03:03,300 --> 00:03:07,260 if the index is greater or equal to the length. 65 00:03:07,260 --> 00:03:09,000 If you got a vector of 10 66 00:03:09,000 --> 00:03:11,010 the last real element is nine. 67 00:03:11,010 --> 00:03:14,910 So if the index is out of bounds, then your program crashes. 68 00:03:14,910 --> 00:03:17,130 Technically it panics. 69 00:03:17,130 --> 00:03:19,560 This is a term that you'll see in Rust. 70 00:03:19,560 --> 00:03:20,640 A program panics, 71 00:03:20,640 --> 00:03:22,800 it basically throws an exception effectively 72 00:03:22,800 --> 00:03:26,580 or it raises an error that causes the program to terminate. 73 00:03:26,580 --> 00:03:29,520 Okay. So when you see panic messages 74 00:03:29,520 --> 00:03:31,590 it means the program has crashed 75 00:03:31,590 --> 00:03:34,920 and the error would be indexed out of bounds. 76 00:03:34,920 --> 00:03:36,390 So obviously you need to fix that. 77 00:03:36,390 --> 00:03:37,530 If you're not sure, 78 00:03:37,530 --> 00:03:40,533 if the index is within range, then check first. 79 00:03:41,640 --> 00:03:43,470 This is an alternative approach. 80 00:03:43,470 --> 00:03:45,000 You can use the get function 81 00:03:45,000 --> 00:03:47,970 as a way of getting a value in a vector. 82 00:03:47,970 --> 00:03:49,770 It returns an option. 83 00:03:49,770 --> 00:03:51,570 Okay. So when you call the get function, 84 00:03:51,570 --> 00:03:52,770 you give it the index 85 00:03:52,770 --> 00:03:55,560 it'll return an option, and this option will 86 00:03:55,560 --> 00:03:58,980 either contain some value if the index is okay 87 00:03:58,980 --> 00:04:02,220 or it'll contain none if the index is invalid. 88 00:04:02,220 --> 00:04:03,360 So what we would typically do then 89 00:04:03,360 --> 00:04:06,120 is you would take this option and check to see 90 00:04:06,120 --> 00:04:08,880 whether it contains a value or not. 91 00:04:08,880 --> 00:04:11,190 You use the match statement like this. 92 00:04:11,190 --> 00:04:13,680 So take the option that came back effectively 93 00:04:13,680 --> 00:04:15,210 like a narrow wrapper. 94 00:04:15,210 --> 00:04:19,410 Take the option it came back and test what it contained. 95 00:04:19,410 --> 00:04:21,090 Does it contain some value? 96 00:04:21,090 --> 00:04:22,980 In which case, give me the value, you know 97 00:04:22,980 --> 00:04:26,550 basically the value at that index, we can the print. 98 00:04:26,550 --> 00:04:28,995 If it contains none, really what it's saying is that 99 00:04:28,995 --> 00:04:33,995 the index was out of bounds and it didn't crash the program 100 00:04:34,020 --> 00:04:36,870 because that would be a little bit, hysterical. 101 00:04:36,870 --> 00:04:40,500 It turned an option, which you can then check to see 102 00:04:40,500 --> 00:04:42,633 if there was no value at that index. 103 00:04:44,490 --> 00:04:48,024 Right, so vector is resizable. 104 00:04:48,024 --> 00:04:52,890 It provides a large set of methods to allow you to insert 105 00:04:52,890 --> 00:04:54,900 and append and to remove 106 00:04:54,900 --> 00:04:57,360 and all kinds of things, and to check the length. 107 00:04:57,360 --> 00:05:00,930 So the documentation for the vector structure is here. 108 00:05:00,930 --> 00:05:02,970 Let's take a look at that. 109 00:05:02,970 --> 00:05:04,230 Here we are. 110 00:05:04,230 --> 00:05:07,260 This is the vector structure 111 00:05:07,260 --> 00:05:12,210 in the Vec module, in the standard crate 112 00:05:12,210 --> 00:05:13,980 and these are the bunch of methods 113 00:05:13,980 --> 00:05:16,020 that are defined in vector. 114 00:05:16,020 --> 00:05:18,060 So like any programming language 115 00:05:18,060 --> 00:05:20,460 when you start using the collection classes 116 00:05:20,460 --> 00:05:22,560 you need to understand the basic premise, 117 00:05:22,560 --> 00:05:24,660 a resizable sequential collection. 118 00:05:24,660 --> 00:05:26,760 And then once you've got the basic idea, 119 00:05:26,760 --> 00:05:28,170 the rest of it is just the details 120 00:05:28,170 --> 00:05:30,030 of what methods it contains. 121 00:05:30,030 --> 00:05:31,950 Okay. So if you look through here, 122 00:05:31,950 --> 00:05:34,350 the method names are actually quite well chosen 123 00:05:34,350 --> 00:05:36,720 and quite intuitive I think, 124 00:05:36,720 --> 00:05:38,523 which isn't true for all languages. 125 00:05:39,750 --> 00:05:41,130 And you've got examples for each one. 126 00:05:41,130 --> 00:05:43,680 So for example, there's a push function. 127 00:05:43,680 --> 00:05:46,350 Let's have a look at some of these examples. 128 00:05:46,350 --> 00:05:49,520 Push function, you give it an item and it appends it, 129 00:05:49,520 --> 00:05:50,730 it puts it at the end 130 00:05:50,730 --> 00:05:52,953 and the vector grows by one element. 131 00:05:54,390 --> 00:05:57,990 The pop function I wonder what the pop function returns. 132 00:05:57,990 --> 00:05:58,890 Let's have a look. 133 00:06:00,150 --> 00:06:02,500 So the pop function removes the last element 134 00:06:02,500 --> 00:06:06,930 from a vector and returns it, it returns an option. 135 00:06:06,930 --> 00:06:09,450 Okay. I guess theoretically, well quite likely, 136 00:06:09,450 --> 00:06:12,150 quite possibly the vector could be empty. 137 00:06:12,150 --> 00:06:15,060 And if you try to pop an element from a empty vector 138 00:06:15,060 --> 00:06:16,770 what could it possibly give you back? 139 00:06:16,770 --> 00:06:18,480 There isn't any value it could give back. 140 00:06:18,480 --> 00:06:20,040 So it does an option. 141 00:06:20,040 --> 00:06:22,830 The option will contain some value 142 00:06:22,830 --> 00:06:24,990 if the vector wasn't empty 143 00:06:24,990 --> 00:06:28,860 or the option would be none if the vector was empty. 144 00:06:28,860 --> 00:06:30,930 Okay. So that actually is quite a good example 145 00:06:30,930 --> 00:06:33,210 of option in practice. 146 00:06:33,210 --> 00:06:35,700 Lots of functions that could possibly return a value 147 00:06:35,700 --> 00:06:36,960 or maybe not. 148 00:06:36,960 --> 00:06:39,600 They wrap the value up in an option to mean 149 00:06:39,600 --> 00:06:41,850 that possibly there may be no value here. 150 00:06:41,850 --> 00:06:43,890 You need to check, you'd need to check 151 00:06:43,890 --> 00:06:46,230 you'd have a a match statement to check 152 00:06:46,230 --> 00:06:50,220 if the option contained a value or if it contained none. 153 00:06:50,220 --> 00:06:53,550 So that actually is quite, quite useful I think. 154 00:06:53,550 --> 00:06:56,820 And then the insert function you insert at a given index 155 00:06:56,820 --> 00:06:58,410 the item you want to insert 156 00:06:58,410 --> 00:07:01,980 and it'll move the other elements one place to the right. 157 00:07:01,980 --> 00:07:05,340 Okay, to make a gap for the new element to be slotted in. 158 00:07:05,340 --> 00:07:07,740 And well, obviously there's a length function as well. 159 00:07:07,740 --> 00:07:09,690 How many elements does my vector contain? 160 00:07:09,690 --> 00:07:11,700 So if the vector has 10 elements 161 00:07:11,700 --> 00:07:14,703 they will be from element zero up to element nine. 162 00:07:16,140 --> 00:07:19,950 Okay, you can iterate over the elements in the vector. 163 00:07:19,950 --> 00:07:21,660 If I've got a vector called V 164 00:07:21,660 --> 00:07:24,720 I can iterate over the items in the vector. 165 00:07:24,720 --> 00:07:28,260 So the basic syntax looks quite straightforward 166 00:07:28,260 --> 00:07:33,260 but notice the ampersand prefix on the vector variable. 167 00:07:33,870 --> 00:07:35,430 We haven't seen that before 168 00:07:35,430 --> 00:07:37,110 and it turns out to be a big deal. 169 00:07:37,110 --> 00:07:41,250 This ampersand, it's called borrowing in Rust. 170 00:07:41,250 --> 00:07:43,440 If you are a C plus plus developer, 171 00:07:43,440 --> 00:07:45,690 you might call it a reference. 172 00:07:45,690 --> 00:07:48,060 When you iterate over a vector, 173 00:07:48,060 --> 00:07:51,450 you've gotta take a reference to the vector. 174 00:07:51,450 --> 00:07:55,200 Basically the fall loop has a reference to the vector object 175 00:07:55,200 --> 00:07:58,890 and then can refer to the elements inside it. 176 00:07:58,890 --> 00:08:01,350 It is required to use the ampersand 177 00:08:01,350 --> 00:08:03,990 when you iterate over a vector. 178 00:08:03,990 --> 00:08:06,450 If you didn't, then the vector contents 179 00:08:06,450 --> 00:08:08,280 will be emptied in the loop. 180 00:08:08,280 --> 00:08:11,070 Okay. So as if you didn't have the ampersand in here, 181 00:08:11,070 --> 00:08:14,700 as you iterate over the loop, the vector will gradually, 182 00:08:14,700 --> 00:08:18,450 the elements in it will be removed during the iteration. 183 00:08:18,450 --> 00:08:21,090 That's quite a complicated mechanism involved here. 184 00:08:21,090 --> 00:08:23,040 It's to do with the ownership model 185 00:08:23,040 --> 00:08:26,490 and borrowing in Rust and it's quite tricky. 186 00:08:26,490 --> 00:08:28,140 So we're gonna have a look at all of that 187 00:08:28,140 --> 00:08:30,420 in quite a lot of detail later. 188 00:08:30,420 --> 00:08:34,740 I'm gonna explain how Rust manages the lifetime of objects 189 00:08:34,740 --> 00:08:39,150 and how you can borrow objects without destroying them. 190 00:08:39,150 --> 00:08:40,740 Quite tricky. 191 00:08:40,740 --> 00:08:41,790 Very important. 192 00:08:41,790 --> 00:08:44,613 We'll discuss it later, in detail. 193 00:08:45,780 --> 00:08:47,430 Right. Well, luckily for us, 194 00:08:47,430 --> 00:08:50,880 the vector type also implements the debug trait. 195 00:08:50,880 --> 00:08:52,920 So in other words, it has a format function. 196 00:08:52,920 --> 00:08:54,540 We can output a vector 197 00:08:54,540 --> 00:08:57,450 using debug formatting in the print lin 198 00:08:57,450 --> 00:09:00,042 you can output a vector object using curly bracket, 199 00:09:00,042 --> 00:09:01,830 colon, question mark 200 00:09:01,830 --> 00:09:06,810 and it will call the FMT, the format function on the vector 201 00:09:06,810 --> 00:09:09,990 to display the continents of the vector in one go, 202 00:09:09,990 --> 00:09:11,790 which is quite useful for debugging. 203 00:09:12,630 --> 00:09:14,730 So let's have a look at the example, 204 00:09:14,730 --> 00:09:16,260 same project as before, 205 00:09:16,260 --> 00:09:19,200 lesson 05, compounds, collections. 206 00:09:19,200 --> 00:09:21,540 We'll have a look at the demo vectors function. 207 00:09:21,540 --> 00:09:22,860 Right. Well here we are. 208 00:09:22,860 --> 00:09:24,543 So in my main code, 209 00:09:26,100 --> 00:09:29,190 we've got some examples we've been looking at previously. 210 00:09:29,190 --> 00:09:31,950 We had tuples we looked at earlier 211 00:09:31,950 --> 00:09:34,440 and we had arrays we looked at early before that. 212 00:09:34,440 --> 00:09:36,000 We're gonna look at vector now. 213 00:09:36,000 --> 00:09:37,800 So let's have a look at demo vectors 214 00:09:39,750 --> 00:09:43,410 and it kind of illustrates the various different techniques 215 00:09:43,410 --> 00:09:46,620 we were looking at doing the PowerPoint slides. 216 00:09:46,620 --> 00:09:49,980 Let's just run it so we can see the output 217 00:09:49,980 --> 00:09:52,030 and then we can discuss as we go through. 218 00:09:57,496 --> 00:09:58,413 Okie-dokie. 219 00:09:59,383 --> 00:10:01,560 I tell you what I forgot to do. 220 00:10:01,560 --> 00:10:03,330 I forgot to actually call the function. 221 00:10:03,330 --> 00:10:04,350 It would help, wouldn't it? 222 00:10:04,350 --> 00:10:06,990 Let's actually call the demo vectors function here, 223 00:10:06,990 --> 00:10:11,990 a deliberate error there and the output is here. 224 00:10:12,370 --> 00:10:14,580 Okay, so we're in the using vectors 225 00:10:14,580 --> 00:10:19,050 that's my headline print statement, using vectors. 226 00:10:19,050 --> 00:10:19,980 Yes, indeed. 227 00:10:19,980 --> 00:10:24,450 So on the vector structure called the new method 228 00:10:24,450 --> 00:10:25,890 it's a static method. 229 00:10:25,890 --> 00:10:27,120 In fact, static methods 230 00:10:27,120 --> 00:10:29,790 in Rust are called associated functions. 231 00:10:29,790 --> 00:10:31,770 We'll come back to that later. 232 00:10:31,770 --> 00:10:33,270 So this is one syntax 233 00:10:33,270 --> 00:10:36,870 for creating a vector of 32 bit integers. 234 00:10:36,870 --> 00:10:38,340 This is the alternative syntax. 235 00:10:38,340 --> 00:10:39,630 Notice that these variables 236 00:10:39,630 --> 00:10:41,490 are put in underscore at the front 237 00:10:41,490 --> 00:10:43,290 'cause I'm not actually using those variables anywhere. 238 00:10:43,290 --> 00:10:46,410 That was just for kind of syntax demonstration purposes. 239 00:10:46,410 --> 00:10:48,540 This is the vector I'm gonna be using, 240 00:10:48,540 --> 00:10:51,990 using the Vecmacro to both create the vector. 241 00:10:51,990 --> 00:10:54,240 It knows what type of elements you've got here. 242 00:10:54,240 --> 00:10:56,766 So it knows it's like a i32 243 00:10:56,766 --> 00:10:59,220 and it'll create a a vector of i32 244 00:10:59,220 --> 00:11:02,043 and push those three elements into it. 245 00:11:03,660 --> 00:11:06,840 Okay. So my vector has three elements. 246 00:11:06,840 --> 00:11:10,020 If I try to access an element within bounds 247 00:11:10,020 --> 00:11:11,520 then that's fine. 248 00:11:11,520 --> 00:11:15,210 It'll be turned back in i32 and 32 bit integer 249 00:11:15,210 --> 00:11:19,260 and the value was a hundred. 250 00:11:19,260 --> 00:11:21,660 At position zero was the value a hundred. 251 00:11:21,660 --> 00:11:22,493 That's good. 252 00:11:23,490 --> 00:11:26,160 I can call the get function if I'm not sure. 253 00:11:26,160 --> 00:11:29,370 If I had an index and I wasn't sure if it was within range, 254 00:11:29,370 --> 00:11:31,590 then get is a safer alternative 255 00:11:31,590 --> 00:11:34,770 to just plow it straight in with the square brackets 256 00:11:34,770 --> 00:11:38,250 returns an option, check that option, 257 00:11:38,250 --> 00:11:39,780 does it contain some value? 258 00:11:39,780 --> 00:11:41,310 In which case give me the value. 259 00:11:41,310 --> 00:11:44,648 I'm getting element zero, so it should give me the value 260 00:11:44,648 --> 00:11:48,693 a hundred again, which is indeed what it gives. 261 00:11:50,850 --> 00:11:52,350 I've pushed some items. 262 00:11:52,350 --> 00:11:53,970 So push means append. 263 00:11:53,970 --> 00:11:58,170 So initially the vector contained a hundred, 101, 264 00:11:58,170 --> 00:12:03,170 102 followed by 103, followed by 104, followed by 105. 265 00:12:05,340 --> 00:12:07,260 It'll remove the last element. 266 00:12:07,260 --> 00:12:09,663 So that's the end of element 105. 267 00:12:10,500 --> 00:12:14,430 And then at the beginning it'll insert 99. 268 00:12:14,430 --> 00:12:17,250 I wonder what the items look like after that. 269 00:12:17,250 --> 00:12:18,660 Let's have a look. 270 00:12:18,660 --> 00:12:20,310 Let's iterate through the vector items. 271 00:12:20,310 --> 00:12:23,142 Remembering the borrowing syntax here, or reference 272 00:12:23,142 --> 00:12:25,230 as you might call it in C plus plus 273 00:12:25,230 --> 00:12:27,060 it is called borrowing in Rust. 274 00:12:27,060 --> 00:12:30,930 So we should call it that, so that when you print 275 00:12:30,930 --> 00:12:32,430 when I print my vector here 276 00:12:32,430 --> 00:12:36,300 it prints each element on a separate line and it is here, 277 00:12:36,300 --> 00:12:37,530 that looks correct to me. 278 00:12:37,530 --> 00:12:39,180 That looks right. 279 00:12:39,180 --> 00:12:42,270 And then finally we can use the debug formatter 280 00:12:42,270 --> 00:12:44,280 to open the vector all in one go, 281 00:12:44,280 --> 00:12:46,050 which is, probably more convenient. 282 00:12:46,050 --> 00:12:47,043 And there it is. 283 00:12:48,510 --> 00:12:52,020 Right. So just before we finish, let's see what happens. 284 00:12:52,020 --> 00:12:56,790 If I try to get an element, which is out of range. 285 00:12:56,790 --> 00:12:59,580 Let's say I try to get the element to position 42 286 00:12:59,580 --> 00:13:01,080 obviously that's not valid. 287 00:13:01,080 --> 00:13:01,920 So in this case 288 00:13:01,920 --> 00:13:04,173 I would expect it to say no value. 289 00:13:05,160 --> 00:13:05,993 Ready, home. 290 00:13:05,993 --> 00:13:07,030 So let's give that a spin. 291 00:13:10,050 --> 00:13:11,070 So there we go. 292 00:13:11,070 --> 00:13:11,903 No value. 293 00:13:11,903 --> 00:13:13,710 That's that output there. 294 00:13:13,710 --> 00:13:17,400 So the get function fails gracefully, it returns an option 295 00:13:17,400 --> 00:13:20,220 which may contain a value or not. 296 00:13:20,220 --> 00:13:22,200 If you use the square brackets operator 297 00:13:22,200 --> 00:13:24,450 then good luck with that. 298 00:13:24,450 --> 00:13:27,156 You need to know for sure that the index is within range. 299 00:13:27,156 --> 00:13:30,780 If it isn't, then the program will basically crash. 300 00:13:30,780 --> 00:13:33,090 It'll terminate, it'll panic. 301 00:13:33,090 --> 00:13:34,230 That's the Rust terminology. 302 00:13:34,230 --> 00:13:36,990 It panics, it crashes with an error message 303 00:13:36,990 --> 00:13:39,450 and the program terminates at that point. 304 00:13:39,450 --> 00:13:42,813 So this will cause a program panic when I run it. 305 00:13:46,470 --> 00:13:50,640 Okay, so the main thread in my application panicked. 306 00:13:50,640 --> 00:13:52,110 In other words 307 00:13:52,110 --> 00:13:55,530 it raised an error that caused the program to crash, 308 00:13:55,530 --> 00:13:56,790 index out of bounds. 309 00:13:56,790 --> 00:13:59,100 That's the name of the error. 310 00:13:59,100 --> 00:14:01,140 Quite a useful error message. 311 00:14:01,140 --> 00:14:04,440 The length of the vector is three, but the index is 42 312 00:14:04,440 --> 00:14:08,640 and it was online 87 in my main code. 313 00:14:08,640 --> 00:14:11,220 Okay, so that's a very comprehensive error message. 314 00:14:11,220 --> 00:14:13,620 My program has terminated, 315 00:14:13,620 --> 00:14:18,620 so there's no way back now, it's a terminal situation 316 00:14:18,660 --> 00:14:19,590 so you'd need to go back 317 00:14:19,590 --> 00:14:22,500 and fix the code so that it would then work properly. 318 00:14:22,500 --> 00:14:25,540 So I'll fix the code, run it again 319 00:14:27,150 --> 00:14:29,580 and this time it's going to work isn't it? 320 00:14:29,580 --> 00:14:30,413 Beautiful.