Created
December 25, 2017 06:57
-
-
Save SilverSoldier/fe3b8a1af3c799d9f45a8ea3764b5d62 to your computer and use it in GitHub Desktop.
Rust macro for hashmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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