Skip to content

Commit 08fd9b7

Browse files
committed
Implement From<[(K, V); N]> for HashMap
1 parent d1d4847 commit 08fd9b7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/map.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,26 @@ where
15801580
}
15811581
}
15821582

1583+
// The default hasher is used to match the std implementation signature
1584+
impl<K, V, A, const N: usize> From<[(K, V); N]> for HashMap<K, V, DefaultHashBuilder, A>
1585+
where
1586+
K: Eq + Hash,
1587+
A: Default + Allocator + Clone,
1588+
{
1589+
/// # Examples
1590+
///
1591+
/// ```
1592+
/// use hashbrown::HashMap;
1593+
///
1594+
/// let map1 = HashMap::from([(1, 2), (3, 4)]);
1595+
/// let map2: HashMap<_, _> = [(1, 2), (3, 4)].into();
1596+
/// assert_eq!(map1, map2);
1597+
/// ```
1598+
fn from(arr: [(K, V); N]) -> Self {
1599+
arr.into_iter().collect()
1600+
}
1601+
}
1602+
15831603
/// An iterator over the entries of a `HashMap`.
15841604
///
15851605
/// This `struct` is created by the [`iter`] method on [`HashMap`]. See its

src/set.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,6 @@ where
11601160
}
11611161

11621162
// The default hasher is used to match the std implementation signature
1163-
// see https://doc.rust-lang.org/src/std/collections/hash/set.rs.html#1010-1026
11641163
impl<T, A, const N: usize> From<[T; N]> for HashSet<T, DefaultHashBuilder, A>
11651164
where
11661165
T: Eq + Hash,

0 commit comments

Comments
 (0)