Zest.

Rust: HashMap

A short, tested Rust example for hashmap. Copy it and adjust the names and paths for your project.

Rust
use std::collections::HashMap;

let mut m = HashMap::new();
m.insert("a", 1);
if let Some(v) = m.get("a") { println!("{v}"); }
*m.entry("a").or_insert(0) += 1;
for (k, v) in &m { println!("{k} {v}"); }

Find it in Zest

Search for “rust hashmap” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Rust examples

All Rust examples