Advertisement
cwchen

[Rust] Iterating a map with its (key, value) pairs.

Aug 23rd, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.31 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. fn main() {
  4.     let mut hash = HashMap::new();
  5.  
  6.     hash.insert("one", "eins");
  7.     hash.insert("two", "zwei");
  8.     hash.insert("three", "drei");
  9.  
  10.     // Iterate the hash by (key, value) pair
  11.     for (k, v) in hash.iter() {
  12.         println!("{} => {}", k, *v);
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement