std-method
BinaryHeap::iter
Borrow each item without consuming the heap. Traversal order is unspecified; use aggregation when order is irrelevant or explicitly sort a report. Expected stdout (not executed): 16 3 Common mistake: Expecting iteration to yield highest priority first.
Formal Syntax & Structure
rust syntaxrust
fn iter(&self) -> Iter<'_, T>Working Example
Example Snippetrust
fn main() { use std::collections::BinaryHeap; let q = BinaryHeap::from([8, 3, 5]); println!("{}", q.iter().sum::<i32>()); println!("{}", q.len());}