Skip to content

Commit 49f5c8b

Browse files
author
Timothée Haudebourg
committed
Use Equivalent trait in HashSet.
1 parent 75a9ef9 commit 49f5c8b

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/set.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::TryReserveError;
1+
use crate::{Equivalent, TryReserveError};
22
use alloc::borrow::ToOwned;
3-
use core::borrow::Borrow;
43
use core::fmt;
54
use core::hash::{BuildHasher, Hash};
65
use core::iter::{Chain, FromIterator, FusedIterator};
@@ -773,8 +772,7 @@ where
773772
#[cfg_attr(feature = "inline-more", inline)]
774773
pub fn contains<Q: ?Sized>(&self, value: &Q) -> bool
775774
where
776-
T: Borrow<Q>,
777-
Q: Hash + Eq,
775+
Q: Hash + Equivalent<T>,
778776
{
779777
self.map.contains_key(value)
780778
}
@@ -800,8 +798,7 @@ where
800798
#[cfg_attr(feature = "inline-more", inline)]
801799
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
802800
where
803-
T: Borrow<Q>,
804-
Q: Hash + Eq,
801+
Q: Hash + Equivalent<T>,
805802
{
806803
// Avoid `Option::map` because it bloats LLVM IR.
807804
match self.map.get_key_value(value) {
@@ -856,8 +853,7 @@ where
856853
#[inline]
857854
pub fn get_or_insert_owned<Q: ?Sized>(&mut self, value: &Q) -> &T
858855
where
859-
T: Borrow<Q>,
860-
Q: Hash + Eq + ToOwned<Owned = T>,
856+
Q: Hash + Equivalent<T> + ToOwned<Owned = T>,
861857
{
862858
// Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with
863859
// `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`.
@@ -889,8 +885,7 @@ where
889885
#[cfg_attr(feature = "inline-more", inline)]
890886
pub fn get_or_insert_with<Q: ?Sized, F>(&mut self, value: &Q, f: F) -> &T
891887
where
892-
T: Borrow<Q>,
893-
Q: Hash + Eq,
888+
Q: Hash + Equivalent<T>,
894889
F: FnOnce(&Q) -> T,
895890
{
896891
// Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with
@@ -1106,8 +1101,7 @@ where
11061101
#[cfg_attr(feature = "inline-more", inline)]
11071102
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool
11081103
where
1109-
T: Borrow<Q>,
1110-
Q: Hash + Eq,
1104+
Q: Hash + Equivalent<T>,
11111105
{
11121106
self.map.remove(value).is_some()
11131107
}
@@ -1133,8 +1127,7 @@ where
11331127
#[cfg_attr(feature = "inline-more", inline)]
11341128
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T>
11351129
where
1136-
T: Borrow<Q>,
1137-
Q: Hash + Eq,
1130+
Q: Hash + Equivalent<T>,
11381131
{
11391132
// Avoid `Option::map` because it bloats LLVM IR.
11401133
match self.map.remove_entry(value) {

0 commit comments

Comments
 (0)