Created
August 6, 2020 14:31
-
-
Save yasukotelin/5d1f9ab5bd50b96b35854f1e0201b3a8 to your computer and use it in GitHub Desktop.
This file contains 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 | |
}} | |
} |
Usage
use std::collections::HashMap;
let hash: HashMap<&str, i32> = hashmap!["hello" => 1, "world" => 2];
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Link: https://www.366service.com/jp/qa/3b42bd30380c728939a2e80b42d430a6