aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/macros.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-core/src/macros.rs')
-rw-r--r--helix-core/src/macros.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/helix-core/src/macros.rs b/helix-core/src/macros.rs
new file mode 100644
index 00000000..1321ea5f
--- /dev/null
+++ b/helix-core/src/macros.rs
@@ -0,0 +1,17 @@
+#[macro_export]
+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
+ }
+ };
+}