From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Demo: Basics of vectors

Demo: Basics of vectors

- [Instructor] Vectors and slices in Rust are, have like a similar relationship as strings and string slices, just like we've seen before. Now let's take a look at some of the differences. So here we have a main function and I would say like one of the main things is that slices, you should see them as almost like fixed in size and they're immutable, not always though so it's, I'm hesitant to say that that's like a mandatory or exclusive thing, but if you think about something that is not growable or that the size can be unknown, then vectors are your, the go-to data structure that you want to use. Otherwise, slices are fine. So let's start with ownership. And I'm going to comment this album, modifiable is going to be comment out and we'll take a look at that in a second. So let's run ownership and let's see what is going on. So we're going to get a sample slice and one, two, and three and let's take a look at what we have here. So first we define the vector. The vector will have…

Contents