| 1 | #[macro_export] |
| 2 | macro_rules! hashmap { |
| 3 | (@single $($x:tt)*) => (()); |
| 4 | (@count $($rest:expr),*) => (<[()]>::len(&[$(hashmap!(@single $rest)),*])); |
| 5 | |
| 6 | ($($key:expr => $value:expr,)+) => { hashmap!($($key => $value),+) }; |
| 7 | ($($key:expr => $value:expr),*) => { |
| 8 | { |
| 9 | let _cap = hashmap!(@count $($key),*); |
| 10 | let mut _map = ::std::collections::HashMap::with_capacity(_cap); |
| 11 | $( |
| 12 | let _ = _map.insert($key, $value); |
| 13 | )* |
| 14 | _map |
| 15 | } |
| 16 | }; |
| 17 | } |