## 方法1
[[HashMap.from]]を使う。
```rust
use std::collections::HashMap;
let m = HashMap::from([(1, 2), (3, 4)]);
print!("{m:?}");
// {3: 4, 1: 2}
```
<button class="playground"><a href="https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9c3ee8d838f8685c0799d5ed3bae39ac">Playground</a></button>
## 方法2
[[maplit]]を使う。
```rust
use maplit::hashmap;
let map = hashmap!{
"a" => 1,
"b" => 2,
};
```
> [!error]
> [[IntelliJ IDEA]] + [[IntelliJ Rust]]ではエラーになってしまった.. (コンパイルは通る)