std-method

BinaryHeap::peek

Inspect the greatest item by shared reference without removing it. This is useful for deciding whether the next scheduled task is ready. Expected stdout (not executed): Some(5) 3 Common mistake: Assuming inspection consumes the item.

Formal Syntax & Structure

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

Working Example

Example Snippetrust
fn main() {    use std::collections::BinaryHeap;    let q = BinaryHeap::from([5, 1, 3]);    println!("{:?}", q.peek());    println!("{}", q.len());}
Rust Reference