From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Vectors

Vectors - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Vectors

- [Instructor] As we approach the end of this course, I want to show you a couple more common data types, you're likely to encounter when programming with Rust. The first of those is the vector which we've already encountered as the return type from some standard functions. A vector holds a collection of elements with the same data type and stores them sequentially in order. That may sound like the definition of an array, but there's a key difference. Arrays have a fixed size that must be known at compile time because array data gets stored on the stack. Vectors on the other hand, can dynamically grow and shrink by adding and removing elements so you do not need to know its size when instantiating a vector. The vectors data is stored on the heap, and therefore we need to handle ownership and borrowing like we would with string data which is also stored on the heat. The code on line two shows the Syntax for creating a…

Contents