Skip to Content
Hands-On Data Structures and Algorithms with Rust
book

Hands-On Data Structures and Algorithms with Rust

by Claus Matzinger
January 2019
Intermediate to advanced
316 pages
8h 8m
English
Packt Publishing
Content preview from Hands-On Data Structures and Algorithms with Rust

Look up

One major upside of using array-type data allocation is the simple and fast element access, which Vec<T> and VecDeque<T> share. The formal way to implement the direct access using brackets (let my_first_element= v[0];) is provided by the Index<I> trait.

Other than direct access, iterators are provided to search, fold, map, and so on the data. Some are equivalent to the LinkedList<T> part of this section.

As an example, the Vec<T>'s owning iterator (IntoIter<T>) owns the pointer to the buffer and moves a pointer to the current element forward. There is also a catch though: if the size of an element is zero bytes, how should the pointer be moved? What data is returned? The IntoIter<T> structure comes up with a clever solution (ZSTs ...

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.
Start your free trial

You might also like

Hands-On Data Structures and Algorithms in Rust

Hands-On Data Structures and Algorithms in Rust

Matthew Stoodley

Publisher Resources

ISBN: 9781788995528Supplemental Content