May 2019
Intermediate to advanced
698 pages
17h 21m
English
The linked list contains two functions: pop_front() and pop_back(), and they simply wrap around an "inner" function called pop_front_node():
#[inline]fn pop_front_node(&mut self) -> Option<Box<Node<T>>> { self.head.map(|node| unsafe { let node = Box::from_raw(node.as_ptr()); self.head = node.next; match self.head { None => self.tail = None, Some(mut head) => head.as_mut().prev = None, } self.len -= 1; node })}
This way, removing a specific element from LinkedList<T> has to be done either by splitting and appending the list (skipping the desired element), or by using drain_filter() function, which does almost exactly that.
Read now
Unlock full access