Created
May 27, 2019 05:34
-
-
Save anonymouss/f7f99b8ea80ebef35d51e4801a4f470f to your computer and use it in GitHub Desktop.
macro in rust
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
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