]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Auto merge of #84111 - bstrie:hashfrom, r=joshtriplett
authorbors <bors@rust-lang.org>
Sat, 24 Jul 2021 22:31:14 +0000 (22:31 +0000)
committerbors <bors@rust-lang.org>
Sat, 24 Jul 2021 22:31:14 +0000 (22:31 +0000)
commit2b4196e97736ffe75433235bf586989cdb4221c4
treeb7a143f874afb6f4348b0161495b0e75799462e4
parentd9aa28767287670df6cf823b94629122e04442c0
parent1b83fedda46d0162952d00f25a60c22028c1e15a
Auto merge of #84111 - bstrie:hashfrom, r=joshtriplett

Stabilize `impl From<[(K, V); N]> for HashMap` (and friends)

In addition to allowing HashMap to participate in Into/From conversion, this adds the long-requested ability to use constructor-like syntax for initializing a HashMap:
```rust
let map = HashMap::from([
    (1, 2),
    (3, 4),
    (5, 6)
]);
```
This addition is highly motivated by existing precedence, e.g. it is already possible to similarly construct a Vec from a fixed-size array:
```rust
let vec = Vec::from([1, 2, 3]);
```
...and it is already possible to collect a Vec of tuples into a HashMap (and vice-versa):
```rust
let vec = Vec::from([(1, 2)]);
let map: HashMap<_, _> = vec.into_iter().collect();
let vec: Vec<(_, _)> = map.into_iter().collect();
```
...and of course it is likewise possible to collect a fixed-size array of tuples into a HashMap ([but not vice-versa just yet](https://github.com/rust-lang/rust/issues/81615)):
```rust
let arr = [(1, 2)];
let map: HashMap<_, _> = std::array::IntoIter::new(arr).collect();
```
Therefore this addition seems like a no-brainer.

As for any impl, this would be insta-stable.
library/alloc/src/collections/binary_heap.rs
library/alloc/src/collections/btree/map.rs
library/alloc/src/collections/btree/set.rs
library/alloc/src/collections/linked_list.rs
library/alloc/src/collections/vec_deque/mod.rs
library/alloc/src/vec/mod.rs
library/std/src/collections/hash/map.rs
library/std/src/collections/hash/set.rs