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 from there. It has to store a pointer to the entire list, along with the current index:
pub struct ListIterator {
current: usize,
data: Box<[Node]>,
}
This struct makes the implementation already obvious...