1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// run-pass use std::collections::HashMap; pub fn main() { let mut h = HashMap::new(); let kvs = [(1, 10), (2, 20), (3, 30)]; for &(k,v) in &kvs { h.insert(k,v); } let mut x = 0; let mut y = 0; for (&k,&v) in &h { x += k; y += v; } assert_eq!(x, 6); assert_eq!(y, 60); }