Skip to content

Commit 6b14b8e

Browse files
committed
Use the Equivalent trait from the equivalent crate
This allows types implementating the `Equivalent` trait to work with other hash table, such as `IndexMap`. See indexmap-rs/indexmap#253.
1 parent 3056ee9 commit 6b14b8e

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Cargo.toml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,22 @@ ahash = { version = "0.8.0", default-features = false, optional = true }
1919
# For external trait impls
2020
rayon = { version = "1.0", optional = true }
2121
serde = { version = "1.0.25", default-features = false, optional = true }
22-
rkyv = { version = "0.7.42", optional = true, default-features = false, features = ["alloc"]}
22+
rkyv = { version = "0.7.42", optional = true, default-features = false, features = [
23+
"alloc",
24+
] }
2325

2426
# When built as part of libstd
2527
core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" }
2628
compiler_builtins = { version = "0.1.2", optional = true }
2729
alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" }
2830

2931
# Support for allocators that use allocator-api2
30-
allocator-api2 = { version = "0.2.9", optional = true, default-features = false, features = ["alloc"] }
32+
allocator-api2 = { version = "0.2.9", optional = true, default-features = false, features = [
33+
"alloc",
34+
] }
35+
36+
# Equivalent trait which can be shared with other hash table implementations.
37+
equivalent = { version = "1.0", optional = true, default-features = false }
3138

3239
[dev-dependencies]
3340
lazy_static = "1.4"
@@ -45,7 +52,13 @@ default = ["ahash", "inline-more", "allocator-api2"]
4552
nightly = ["allocator-api2?/nightly", "bumpalo/allocator_api"]
4653

4754
rustc-internal-api = []
48-
rustc-dep-of-std = ["nightly", "core", "compiler_builtins", "alloc", "rustc-internal-api"]
55+
rustc-dep-of-std = [
56+
"nightly",
57+
"core",
58+
"compiler_builtins",
59+
"alloc",
60+
"rustc-internal-api",
61+
]
4962
raw = []
5063

5164
# Enables usage of `#[inline]` on far more functions than by default in this

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ pub mod hash_set {
117117
pub use crate::map::HashMap;
118118
pub use crate::set::HashSet;
119119

120+
#[cfg(feature = "equivalent")]
121+
use equivalent::Equivalent;
122+
123+
// This is only used as a fallback when building as part of `std`.
124+
#[cfg(not(feature = "equivalent"))]
120125
/// Key equivalence trait.
121126
///
122127
/// This trait defines the function used to compare the input value with the
@@ -140,6 +145,7 @@ pub trait Equivalent<K: ?Sized> {
140145
fn equivalent(&self, key: &K) -> bool;
141146
}
142147

148+
#[cfg(not(feature = "equivalent"))]
143149
impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q
144150
where
145151
Q: Eq,

0 commit comments

Comments
 (0)