Skip to content

Instantly share code, notes, and snippets.

@totechite
Last active November 15, 2019 06:12
Show Gist options
  • Save totechite/3dcc719448a54b00f5df546845428755 to your computer and use it in GitHub Desktop.
Save totechite/3dcc719448a54b00f5df546845428755 to your computer and use it in GitHub Desktop.
[Rust]
fn main() {
use std::collections::HashMap;
//マクロの定義
macro_rules! hash {
( $( $t:expr),* ) => {
{
let mut temp_hash = HashMap::new();
$(
temp_hash.insert($t.0, $t.1);
)*
temp_hash
}
};
}
let result = hash![("apple", 2), ("banana", 1), ("orange", 4)];
for (key, value) in result {
println!("{}: {}", key, value);
//banana: 1
//orange: 4
//apple: 2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment