programmieren-in-rust/aufgaben/sheet9/sol3/map.rs
2017-01-09 18:43:55 +01:00

16 lines
372 B
Rust
Executable File

macro_rules! hash_map {
( $($key:expr => $value:expr ,)* ) => {{
let mut map = ::std::collections::HashMap::new();
$( map.insert($key, $value); )*
map
}};
( $($key:expr => $value:expr),* ) => { hash_map!($($key => $value ,)*) };
}
fn main() {
let ages = hash_map!{ "Sabine" => 26, "Peter" => 32 };
println!("{:#?}", ages);
}