std-method

BinaryHeap::pop

Remove and own the greatest remaining item. An empty queue returns None. Repeated pops produce descending order according to Ord. Expected stdout (not executed): Some(8) Some(3) Some(1) None Common mistake: Unwrapping the result when the queue can be empty.

Formal Syntax & Structure

rust syntaxrust
fn pop(&mut self) -> Option<T>

Working Example

Example Snippetrust
fn main() {    use std::collections::BinaryHeap;    let mut q = BinaryHeap::from([3, 8, 1]);    for _ in 0..4 { println!("{:?}", q.pop()); }}
Rust Reference