std-type
BTreeMap<K, V> — ordered dictionary
Choose this map when a report must appear by key or when a query selects a contiguous interval of keys. Ordinary insertion and lookup require K: Ord. Iteration follows key order rather than arrival order. Expected stdout (not executed): 9: plan 11: build 14: review Common mistake: Assuming the values themselves are sorted.
Formal Syntax & Structure
rust syntaxrust
BTreeMap<K, V>Working Example
Example Snippetrust
fn main() { use std::collections::BTreeMap; let schedule = BTreeMap::from([(14, "review"), (9, "plan"), (11, "build")]); for (hour, task) in &schedule { println!("{hour}: {task}"); }}