Skip to content

Instantly share code, notes, and snippets.

@anonymouss
Created May 27, 2019 05:34
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