January 2019
Intermediate to advanced
316 pages
8h 8m
English
The collections::LinkedList relies a lot on the Iterator trait to look up various items, which is great since it saves a lot of effort. This is achieved by extensively implementing various iterator traits using several structures, like the following:
Technically, DrainFilter also implements Iterator, but it's really a convenience wrapper. The following is the Iter structure declaration that the LinkedList uses:
#[stable(feature = "rust1", since = "1.0.0")] pub struct Iter<'a, T: 'a> { head: Option<NonNull<Node<T>>>, tail: Option<NonNull<Node<T>>>, len: usize, marker: PhantomData<&'a Node<T>>, }
If you remember the list's declaration earlier, it will become obvious that they are very similar! In fact, they are ...