Removes and returns the least recently used value. Returns `None` if the queue is empty.
(&mut self)
| 136 | /// Removes and returns the least recently used value. |
| 137 | /// Returns `None` if the queue is empty. |
| 138 | pub fn pop(&mut self) -> Option<(K, V)> { |
| 139 | let key_to_remove = self.queue.tail.as_ref().map(|n| { |
| 140 | n.upgrade() |
| 141 | .expect("value has been unexpectedly dropped") |
| 142 | .lock() |
| 143 | .key |
| 144 | .clone() |
| 145 | }); |
| 146 | if let Some(k) = key_to_remove { |
| 147 | let value = self.remove(&k).unwrap(); // confirmed above that the entry exists |
| 148 | Some((k, value)) |
| 149 | } else { |
| 150 | None |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /// Removes a specific entry from the queue, if it exists. |
| 155 | pub fn remove(&mut self, key: &K) -> Option<V> { |