A slice is a region of an array or vector that can be any link.
Slices cannot be stored directly into variables or passed as function arguments.
So let's start off by creating our first slice, and I'm going to continue off the vector example we
had in the last lecture.
So we're going to say let s, v and I'm s is for slice a reference of type I 32 equals.
A reference to the vector we created above.
So now I know I said that we cannot store.
Slices directly into a variable.
And that's not what we're doing here.
So what we're actually doing is we are pointing the variable to the address and memory where the slice
starts.
So currently we're pointing SV to where our slice starts in our slice in this case is going to be all
of the vector we created above.
And that reference to the slice is called a fat pointer, which is a two word value comprising a pointer
of the slices first element and the number of elements in the slice.
So now let's just go ahead and print out the vector above.
And then let's go down here and let's point out.
Point, print out.
Our slice.
So you can see they're the same exact thing because we are.
Pointing to the entire vector as our slice.
But if I wanted to, I could point to, let's say, elements 2 to 4.
And now you can see that's exactly what I get.
I get only two and three now.
So we have created our first slice.
So the savvy variable is going to point directly to the data and vector V and it is going to be a non
owning reference and references and ownership.
We will all get to that a little later in this course.
So if it doesn't make sense right now, that's okay.
I just want to introduce some of these concepts to you.
That way when we get to that point in the lectures, it's not a brand new introduction.
So continuing on a little bit more about what references are an ordinary reference is a non owning pointer
to a single value, but a reference to a slice is a non owning pointer to a range of consecutive values.
So again, a ordinary reference points to a single value, whereas a slice points to a range of consecutive
values, both of which are non owning.
So what are sliced references good for?
Well, when you want to write a function that operates on either an array or a vector, that is when
you want to use a slice.
So again, if this didn't make complete sense, it will when we get a little later on into lectures.
It is just something that I wanted to introduce to you.
Prior to getting into strings, which I will begin talking about in the next lecture.