1 00:00:06,450 --> 00:00:10,290 A slice is a region of an array or vector that can be any link. 2 00:00:10,470 --> 00:00:16,500 Slices cannot be stored directly into variables or passed as function arguments. 3 00:00:16,800 --> 00:00:23,280 So let's start off by creating our first slice, and I'm going to continue off the vector example we 4 00:00:23,280 --> 00:00:24,870 had in the last lecture. 5 00:00:25,110 --> 00:00:36,870 So we're going to say let s, v and I'm s is for slice a reference of type I 32 equals. 6 00:00:38,280 --> 00:00:41,490 A reference to the vector we created above. 7 00:00:41,820 --> 00:00:45,570 So now I know I said that we cannot store. 8 00:00:46,620 --> 00:00:48,840 Slices directly into a variable. 9 00:00:49,470 --> 00:00:51,710 And that's not what we're doing here. 10 00:00:51,720 --> 00:00:59,490 So what we're actually doing is we are pointing the variable to the address and memory where the slice 11 00:00:59,490 --> 00:01:00,420 starts. 12 00:01:00,420 --> 00:01:07,440 So currently we're pointing SV to where our slice starts in our slice in this case is going to be all 13 00:01:07,440 --> 00:01:09,240 of the vector we created above. 14 00:01:09,600 --> 00:01:19,680 And that reference to the slice is called a fat pointer, which is a two word value comprising a pointer 15 00:01:19,680 --> 00:01:25,410 of the slices first element and the number of elements in the slice. 16 00:01:26,430 --> 00:01:31,590 So now let's just go ahead and print out the vector above. 17 00:01:36,980 --> 00:01:41,180 And then let's go down here and let's point out. 18 00:01:41,720 --> 00:01:43,250 Point, print out. 19 00:01:44,800 --> 00:01:45,760 Our slice. 20 00:01:49,780 --> 00:01:53,410 So you can see they're the same exact thing because we are. 21 00:01:54,450 --> 00:01:57,150 Pointing to the entire vector as our slice. 22 00:01:57,150 --> 00:02:03,630 But if I wanted to, I could point to, let's say, elements 2 to 4. 23 00:02:07,140 --> 00:02:09,780 And now you can see that's exactly what I get. 24 00:02:09,780 --> 00:02:11,940 I get only two and three now. 25 00:02:11,940 --> 00:02:14,520 So we have created our first slice. 26 00:02:15,680 --> 00:02:25,880 So the savvy variable is going to point directly to the data and vector V and it is going to be a non 27 00:02:25,880 --> 00:02:29,780 owning reference and references and ownership. 28 00:02:29,780 --> 00:02:33,680 We will all get to that a little later in this course. 29 00:02:34,550 --> 00:02:36,910 So if it doesn't make sense right now, that's okay. 30 00:02:36,920 --> 00:02:39,380 I just want to introduce some of these concepts to you. 31 00:02:39,380 --> 00:02:46,550 That way when we get to that point in the lectures, it's not a brand new introduction. 32 00:02:47,970 --> 00:02:55,410 So continuing on a little bit more about what references are an ordinary reference is a non owning pointer 33 00:02:55,410 --> 00:03:03,780 to a single value, but a reference to a slice is a non owning pointer to a range of consecutive values. 34 00:03:04,200 --> 00:03:13,770 So again, a ordinary reference points to a single value, whereas a slice points to a range of consecutive 35 00:03:13,770 --> 00:03:17,190 values, both of which are non owning. 36 00:03:18,120 --> 00:03:21,120 So what are sliced references good for? 37 00:03:21,150 --> 00:03:27,450 Well, when you want to write a function that operates on either an array or a vector, that is when 38 00:03:27,450 --> 00:03:29,350 you want to use a slice. 39 00:03:29,370 --> 00:03:35,320 So again, if this didn't make complete sense, it will when we get a little later on into lectures. 40 00:03:35,340 --> 00:03:38,340 It is just something that I wanted to introduce to you. 41 00:03:39,030 --> 00:03:44,670 Prior to getting into strings, which I will begin talking about in the next lecture.