Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Created June 1, 2017 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DmitrySoshnikov/621241bf461f37a8c8cceef11d0a18d3 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/621241bf461f37a8c8cceef11d0a18d3 to your computer and use it in GitHub Desktop.
macro_rules! map(
{ $($key:expr => $value:expr),+ } => {
{
let mut m = ::std::collections::HashMap::new();
$(
m.insert($key, $value);
)+
m
}
};
);
fn main() {
let names = map!{ 1 => "one", 2 => "two" };
println!("{} -> {:?}", 1, names.get(&1));
println!("{} -> {:?}", 10, names.get(&10));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment