Skip to content

Instantly share code, notes, and snippets.

@anonymouss
Created May 27, 2019 05:34
Show Gist options
  • Save anonymouss/f7f99b8ea80ebef35d51e4801a4f470f to your computer and use it in GitHub Desktop.
Save anonymouss/f7f99b8ea80ebef35d51e4801a4f470f to your computer and use it in GitHub Desktop.
macro in rust
macro_rules! hashmap {
($($key: expr => $val: expr), *) => {{
let mut map = ::std::collections::HashMap::new();
$(map.insert($key, $val);)*
map
}};
}
fn main() {
let counts = hashmap!['A' => 0, 'C' => 1, 'G' => 2, 'T' => 3];
for (k, v) in counts {
println!("{:?} => {:?}", k, v);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment