std-method

BinaryHeap::with_capacity

Request storage for at least the stated number of items before inserting them. Length starts at zero; actual capacity can exceed the request. Expected stdout (not executed): 0 true Common mistake: Confusing allocated capacity with existing elements.

Formal Syntax & Structure

rust syntaxrust
fn with_capacity(capacity: usize) -> BinaryHeap<T>

Working Example

Example Snippetrust
fn main() {    use std::collections::BinaryHeap;    let heap: BinaryHeap<i32> = BinaryHeap::with_capacity(12);    println!("{} {}", heap.len(), heap.capacity() >= 12);}
Rust Reference