macro_rules! hashmap {
() => { ... };
( $( $key:expr => $value:expr ),* ) => { ... };
}Expand description
Just like vec!, but for std::collections::HashMap.
This macro uses count_args! to preallocate the exact amount of memory
needed, so it’s more efficient than simply iteratively inserting.
#[macro_use] extern crate colmac;
use std::collections::HashMap;
// create an empty one
let empty: HashMap<u64, u64> = hashmap![];
assert_eq!(0, empty.len());
// literal initialization
let mut map_a = HashMap::new();
map_a.insert("a", 123);
map_a.insert("b", 456);
let map_b = hashmap!["a" => 123, "b" => 456];
assert_eq!(map_a, map_b);