Vec<T> and VecDeque<T>
Just like the dynamic array in Chapter 14, Lists, Lists, More Lists, Vec<T> and VecDeque<T> are growable, list-like data structures with support for indexing and based on a heap-allocated array. Other than the previously implemented dynamic array, it is generic by default without any constraints for the generic type, allowing literally any type to be used.
Vec<T> aims to have as little overhead as possible, while providing a few guarantees. At its core, it is a triple of (pointer, length, capacity) that provides an API to modify these elements. The capacity is the amount of memory that is allocated to hold items, which means that it fundamentally differs from length, the number of elements currently held. In case a ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access