add map! and set! macros.
@@ -30,3 +30,25 @@ macro_rules! line_error {
concat!($string, " @", file!(), ":", line!())
};
}
+
+/// Creates a simple map using `map! { "key" => "value"}
+#[allow(unused_macros)]
+#[macro_export]
+macro_rules! map {
+ ($($key:expr => $val:expr),* $(,)?) => {{
+ let mut map = HashMap::new();
+ $( map.insert($key, $val); )*
+ map
+ }}
+}
+
+/// Creates a simple HashSet using set! {"val_1", "val_2", ...};
+#[allow(unused_macros)]
+#[macro_export]
+macro_rules! set {
+ ($($val:expr),* $(,)?) => {{ #[allow(redundant_semicolons)] {
+ let mut set = HashSet::new();
+ $( set.insert($val); )* ;
+ set
+ }}}
+}
