From cd067503a7546eaee904a9b5c6ae30eb0175d376 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Mon, 8 Nov 2021 18:06:56 +0000 Subject: [rust] Macros --- rust/macros/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 rust/macros/src/lib.rs (limited to 'rust/macros/src/lib.rs') diff --git a/rust/macros/src/lib.rs b/rust/macros/src/lib.rs new file mode 100644 index 0000000..267aa46 --- /dev/null +++ b/rust/macros/src/lib.rs @@ -0,0 +1,12 @@ + +#[macro_export] +macro_rules! hashmap { + ( $($k:expr => $v:expr),+, ) => { $crate::hashmap!($($k => $v),+) }; + ( $($k:expr => $v:expr),* ) => { + { + let mut hm = ::std::collections::HashMap::new(); + $( hm.insert($k, $v); )* + hm + } + }; +} -- cgit v1.2.3