shlogg · Early preview
Jeff Mitchell @sentinel1909

Learning Rust Vectors In Depth

Vectors in Rust are a collection that can grow/shrink in size, storing items next to each other in heap memory. Created with `Vec::new()` or initialized with values, elements accessed/modified using indexing or `.get()`.

Introduction

Today I resume my journey through the Rust Book, in the spotlight is the vector type.
The Rust Book introduces vectors as a "collection". A vector is similar to an array type, but with the critical difference that a vector can grow and shrink in size. A vector is capable of grouping items into a single data structure. All the individual values in a vector are stored next to each other in heap memory. Vectors can only store data of the same type.
I called this article "The Mighty Vector" because vectors are an extremely versatile and useful way of storing data. I think you'll use...