mirror of
https://github.com/LukasKalbertodt/programmieren-in-rust.git
synced 2024-11-18 10:58:57 +01:00
16 lines
372 B
Rust
16 lines
372 B
Rust
|
|
||
|
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);
|
||
|
}
|