Skip to content

Commit 388dc76

Browse files
authored
Allow all hashers in hashmaps (#941)
1 parent b297509 commit 388dc76

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/container.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::*;
44
use alloc::collections::LinkedList;
5+
use core::hash::BuildHasher;
56
use hashbrown::HashSet;
67

78
/// A utility trait for types that can be constructed from a series of items.
@@ -92,38 +93,40 @@ impl Container<char> for String {
9293
}
9394
}
9495

95-
impl<K: Eq + Hash, V> Container<(K, V)> for HashMap<K, V> {
96+
impl<K: Eq + Hash, V, S: Default + BuildHasher> Container<(K, V)> for HashMap<K, V, S> {
9697
fn with_capacity(n: usize) -> Self {
97-
Self::with_capacity(n)
98+
Self::with_capacity_and_hasher(n, Default::default())
9899
}
99100
fn push(&mut self, (key, value): (K, V)) {
100101
(*self).insert(key, value);
101102
}
102103
}
103104

104105
#[cfg(feature = "std")]
105-
impl<K: Eq + Hash, V> Container<(K, V)> for std::collections::HashMap<K, V> {
106+
impl<K: Eq + Hash, V, S: Default + BuildHasher> Container<(K, V)>
107+
for std::collections::HashMap<K, V, S>
108+
{
106109
fn with_capacity(n: usize) -> Self {
107-
Self::with_capacity(n)
110+
Self::with_capacity_and_hasher(n, Default::default())
108111
}
109112
fn push(&mut self, (key, value): (K, V)) {
110113
(*self).insert(key, value);
111114
}
112115
}
113116

114-
impl<T: Eq + Hash> Container<T> for HashSet<T> {
117+
impl<T: Eq + Hash, S: Default + BuildHasher> Container<T> for HashSet<T, S> {
115118
fn with_capacity(n: usize) -> Self {
116-
Self::with_capacity(n)
119+
Self::with_capacity_and_hasher(n, Default::default())
117120
}
118121
fn push(&mut self, item: T) {
119122
(*self).insert(item);
120123
}
121124
}
122125

123126
#[cfg(feature = "std")]
124-
impl<T: Eq + Hash> Container<T> for std::collections::HashSet<T> {
127+
impl<T: Eq + Hash, S: Default + BuildHasher> Container<T> for std::collections::HashSet<T, S> {
125128
fn with_capacity(n: usize) -> Self {
126-
Self::with_capacity(n)
129+
Self::with_capacity_and_hasher(n, Default::default())
127130
}
128131
fn push(&mut self, item: T) {
129132
(*self).insert(item);
@@ -570,7 +573,7 @@ impl<'p, T: Clone> Seq<'p, T> for LinkedList<T> {
570573
}
571574
}
572575

573-
impl<'p, T: Clone + Eq + Hash> Seq<'p, T> for HashSet<T> {
576+
impl<'p, T: Clone + Eq + Hash, S: BuildHasher> Seq<'p, T> for HashSet<T, S> {
574577
type Item<'a>
575578
= &'a T
576579
where
@@ -598,13 +601,14 @@ impl<'p, T: Clone + Eq + Hash> Seq<'p, T> for HashSet<T> {
598601
fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
599602
where
600603
'p: 'b,
604+
S: 'b,
601605
{
602606
MaybeRef::Val(item.clone())
603607
}
604608
}
605609

606610
#[cfg(feature = "std")]
607-
impl<'p, T: Clone + Eq + Hash> Seq<'p, T> for std::collections::HashSet<T> {
611+
impl<'p, T: Clone + Eq + Hash, S: BuildHasher> Seq<'p, T> for std::collections::HashSet<T, S> {
608612
type Item<'a>
609613
= &'a T
610614
where
@@ -632,6 +636,7 @@ impl<'p, T: Clone + Eq + Hash> Seq<'p, T> for std::collections::HashSet<T> {
632636
fn to_maybe_ref<'b>(item: Self::Item<'b>) -> MaybeRef<'p, T>
633637
where
634638
'p: 'b,
639+
S: 'b,
635640
{
636641
MaybeRef::Val(item.clone())
637642
}

0 commit comments

Comments
 (0)