Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created May 30, 2019 05:52
Show Gist options
  • Save hikilaka/83b77dde19ed1e92bd7ea5377582e113 to your computer and use it in GitHub Desktop.
Save hikilaka/83b77dde19ed1e92bd7ea5377582e113 to your computer and use it in GitHub Desktop.
macro_rules! hashmap {
($($key:expr => $value:expr), +) => ({
let mut map = std::collections::HashMap::new();
$(
map.insert($key, $value);
)+
map
});
}
fn main() {
let map = hashmap!{ 1 => "one", 2 => "two", 3 => "three" };
println!("{:?}", map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment