Rust's std::collection::LinkedList<T> is a doubly linked list that uses an unsafe pointer operation to get around the Rc<RefCell<Node<T>>> unpacking we had to do in Chapter 4, Lists, Lists, and More Lists. While unsafe, this is a great solution to that problem, since the pointer operations are easy to comprehend and provide significant benefits. Let's look at the following code:
#[stable(feature = "rust1", since = "1.0.0")] pub struct LinkedList<T> { head: Option<NonNull<Node<T>>>, tail: Option<NonNull<Node<T>>>, len: usize, marker: PhantomData<Box<Node<T>>>, } struct Node<T> { next: Option<NonNull<Node<T>>>, prev: Option<NonNull<Node<T>>>, element: T, }
NonNull is a structure that originates from std::ptr::NonNull, which provides a non-zero pointer to a portion of heap memory in unsafe...