programmieren-in-rust/aufgaben/sheet09/sol3/map.rs

16 lines
372 B
Rust
Raw Normal View History

2017-01-09 18:43:34 +01:00
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);
}