Skip to content

Commit 74f1bfe

Browse files
committed
feat: hash_map macro
1 parent 8c12d76 commit 74f1bfe

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

library/alloc/src/macros.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,18 @@ macro_rules! format {
109109
})
110110
}
111111
}
112+
113+
#[macro_export]
114+
#[allow_internal_unstable(hint_must_use)]
115+
#[rustc_diagnostic_item = "hash_map_macro"]
116+
macro_rules! hash_map {
117+
() => {{
118+
::std::collections::HashMap::new()
119+
}};
120+
121+
( $( $key:expr => $value:expr ),* $(,)? ) => {{
122+
let mut __map = ::std::collections::HashMap::new();
123+
$( __map.insert($key, $value); )*
124+
__map
125+
}}
126+
}

0 commit comments

Comments
 (0)