macro_rules! hash_map {
(with $map:expr; insert { $($key:expr => $val:expr),* , }) => { ... };
(with $map:expr; insert { $($key:expr => $val:expr),* }) => { ... };
($($key:expr => $val:expr),* ,) => { ... };
($($key:expr => $val:expr),*) => { ... };
}Expand description
Macro to crate a HashMap with a number of key-value pairs in it.
There is an alternate syntax, which allows insertion into an existing
map (and still uses const_expr_count! to call map.reserve() with).
ยงExamples
use common_macros::hash_map;
let is_fun_map = hash_map!{
"joke" => true,
"cat" => true,
};use std::collections::HashMap;
use common_macros::hash_map;
fn setup_map() -> HashMap<u8,u8> {
HashMap::new()
}
let mut map = hash_map!(with setup_map(); insert {
12 => 13,
13 => 56
});
hash_map!(with &mut map; insert {
44 => 45,
48 => 112,
1 => 4
});