Skip to content

Instantly share code, notes, and snippets.

@tnibert
Created December 10, 2021 10:32
Show Gist options
  • Save tnibert/f06c67f15b768378280c8a3d51e47662 to your computer and use it in GitHub Desktop.
Save tnibert/f06c67f15b768378280c8a3d51e47662 to your computer and use it in GitHub Desktop.
Rust hashmap example usage code
// hashmap example - for reference
let mut sample: HashMap<String, i32> = HashMap::new();
sample.insert("one".to_string(), 1);
sample.insert("two".to_string(), 2);
sample.insert("three".to_string(), 3);
sample.insert("four".to_string(), 4);
for (key, value) in sample.iter() {
println!("{} - {}", key, value);
}
println!("four: {:?}", sample.get("four").unwrap());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment