diff options
Diffstat (limited to 'helix-term/src/macros.rs')
-rw-r--r-- | helix-term/src/macros.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/helix-term/src/macros.rs b/helix-term/src/macros.rs new file mode 100644 index 00000000..3b22a786 --- /dev/null +++ b/helix-term/src/macros.rs @@ -0,0 +1,16 @@ +macro_rules! hashmap { + (@single $($x:tt)*) => (()); + (@count $($rest:expr),*) => (<[()]>::len(&[$(hashmap!(@single $rest)),*])); + + ($($key:expr => $value:expr,)+) => { hashmap!($($key => $value),+) }; + ($($key:expr => $value:expr),*) => { + { + let _cap = hashmap!(@count $($key),*); + let mut _map = ::std::collections::HashMap::with_capacity(_cap); + $( + let _ = _map.insert($key, $value); + )* + _map + } + }; +} |