Removes the given node from the list.
(&mut self, node: Rc<RefCell<CacheItem>>)
| 99 | |
| 100 | /// Removes the given node from the list. |
| 101 | fn remove_node(&mut self, node: Rc<RefCell<CacheItem>>) { |
| 102 | let prev_weak = node.borrow_mut().prev.take(); |
| 103 | let next_opt = node.borrow_mut().next.take(); |
| 104 | |
| 105 | if let Some(ref prev_weak_ref) = prev_weak { |
| 106 | if let Some(prev_rc) = prev_weak_ref.upgrade() { |
| 107 | prev_rc.borrow_mut().next = next_opt.clone(); |
| 108 | } |
| 109 | } else { |
| 110 | // Node is head |
| 111 | self.head = next_opt.clone(); |
| 112 | } |
| 113 | |
| 114 | if let Some(next_rc) = next_opt { |
| 115 | next_rc.borrow_mut().prev = prev_weak.clone(); |
| 116 | } else { |
| 117 | // Node is tail |
| 118 | if let Some(ref prev_weak_ref) = prev_weak { |
| 119 | self.tail = prev_weak_ref.upgrade(); |
| 120 | } else { |
| 121 | // List is empty |
| 122 | self.tail = None; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /// Adds the given node to the front of the list. |
| 128 | fn add_to_head(&mut self, node: Rc<RefCell<CacheItem>>) { |
no outgoing calls
no test coverage detected