impl Node { fn new(v: T) -> Node { Node {value: v, next: None, prev: Rawlink::none()} } } impl Rawlink { fn none() -> Self { Rawlink {p: ptr::null_mut()} } fn some(n: &mut T) -> Rawlink { Rawlink{p: n} } } impl<'a, T> From<&'a mut Link> for Rawlink> { fn from(node: &'a mut Link) -> Self { match node.as_mut() { None => Rawlink::none(), Some(ptr) => Rawlink::some(ptr) } } } fn link_no_prev(mut next: Box>) -> Link { next.prev = Rawlink::none(); Some(next) } impl LinkedList { #[inline] fn push_front_node(&mut self, mut new_head: Box>) { match self.list_head { None => { self.list_head = link_no_prev(new_head); self.list_tail = Rawlink::from(&mut self.list_head); } Some(ref mut head) => { new_head.prev = Rawlink::none(); head.prev = Rawlink::some(&mut *new_head); mem::swap(head, &mut new_head); head.next = Some(new_head); } } self.length += 1; } pub fn push_front(&mut self, elt: T) { self.push_front_node(Box::new(Node::new(elt))); } }