std-method
PeekMut::pop
Consume the guard and remove the item it currently accesses. If that item was changed through the guard, the returned value reflects the change. Expected stdout (not executed): 7 Some(4) Common mistake: Trying to call heap.pop while its mutable guard is still held.
Formal Syntax & Structure
rust syntaxrust
fn pop(this: PeekMut<'_, T>) -> TWorking Example
Example Snippetrust
fn main() { use std::collections::BinaryHeap; use std::collections::binary_heap::PeekMut; let mut q = BinaryHeap::from([7, 4, 2]); let top = q.peek_mut().unwrap(); println!("{}", PeekMut::pop(top)); println!("{:?}", q.peek());}