Iterate over key-value pairs in a Hash



examples/hashes/iterate-over-pairs/src/main.rs
use std::collections::HashMap;

fn main() {
    let counter = HashMap::from([("foo", 1), ("bar", 2)]);
    println!("{:?}", counter);
    println!("{:?}", counter.keys());

    for (name, value) in counter.iter() {
        println!("{} : {}", name, value);
    }
    println!();

    for (name, value) in counter {
        println!("{} : {}", name, value);
    }
}

{"bar": 2, "foo": 1}
["bar", "foo"]
bar : 2
foo : 1

bar : 2
foo : 1