BTreeMap in Rust
An ordered map: iteration follows the keys, and you can ask for a range.
use std::collections::BTreeMap;
fn main() {
let mut runs = BTreeMap::new();
runs.insert("2026-07-02", 91);
runs.insert("2026-07-29", 104);
runs.insert("2026-07-14", 98);
for (day, tpm) in &runs {
println!("{day} {tpm}");
}
for (day, tpm) in runs.range("2026-07-10".."2026-07-20") {
println!("mid month: {day} {tpm}");
}
println!("{:?}", runs.first_key_value());
}
How it works
- Keys stay sorted, so iteration is deterministic.
rangeselects a slice of the key space.first_key_valuereads the smallest entry.
Keywords and builtins used here
fnforinletmainmutuse
The run, in numbers
- Lines
- 18
- Characters to type
- 367
- Tokens
- 115
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 77 seconds.
Step 7 of 8 in Collections, step 36 of 39 in Language basics.