January 2019
Intermediate to advanced
316 pages
8h 8m
English
Due to the underlying slice, accessing an index is cheap. In fact, it always takes the same amount of time, regardless of the index (which makes it different to previously discussed lists). A call to the at() function will therefore simply forward it accordingly:
pub fn at(&mut self, index: usize) -> Option<u64> { if self.length > index { self.buf[index] } else { None }}
Here, again, the Rust implementation has to deal with sharing borrowed content or clone the data structure which might require more memory. Under the hood, a u64 is implicitly cloned.
To fulfill all requirements, the Iterator trait has to be implemented as well. Unlike the doubly linked list, the iterator cannot store a single node and go forward or backward ...