Created
April 15, 2018 14:05
-
-
Save PurpleMyst/f371c143dce70c20ec587f65053551dd to your computer and use it in GitHub Desktop.
A macro for an HashMap literal written in Rust.
This file contains 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_rules! hashmap { | |
{$($key:expr => $value:expr),*} => {{ | |
let mut __hm = HashMap::new(); | |
$( | |
__hm.insert($key, $value); | |
)* | |
__hm | |
}} | |
} | |
fn main() { | |
let hm = hashmap!{1 => 2, 3 => 4}; | |
println!("{:?}", hm); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment