Skip to content

Instantly share code, notes, and snippets.

@SilverSoldier
Created December 25, 2017 06:57
Show Gist options
  • Save SilverSoldier/fe3b8a1af3c799d9f45a8ea3764b5d62 to your computer and use it in GitHub Desktop.
Save SilverSoldier/fe3b8a1af3c799d9f45a8ea3764b5d62 to your computer and use it in GitHub Desktop.
Rust macro for hashmap
use std::collections::HashMap;
#[macro_export]
macro_rules! map (
{$($key:expr => $value:expr), + } => {
{
let mut m = HashMap::new();
$(
m.insert($key, $value);
)+
m
}
};
);
pub fn abc() {
let numbers = map!{ 1 => "one", 2 => "two" };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment