Skip to content

Commit

Permalink
Auto merge of #442 - Amanieu:equivalent-crate, r=Amanieu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jul 9, 2023
2 parents 25e60a2 + 6b14b8e commit 3b348ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ ahash = { version = "0.8.0", default-features = false, optional = true }
# For external trait impls
rayon = { version = "1.0", optional = true }
serde = { version = "1.0.25", default-features = false, optional = true }
rkyv = { version = "0.7.42", optional = true, default-features = false, features = ["alloc"]}
rkyv = { version = "0.7.42", optional = true, default-features = false, features = [
"alloc",
] }

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

# Support for allocators that use allocator-api2
allocator-api2 = { version = "0.2.9", optional = true, default-features = false, features = ["alloc"] }
allocator-api2 = { version = "0.2.9", optional = true, default-features = false, features = [
"alloc",
] }

# Equivalent trait which can be shared with other hash table implementations.
equivalent = { version = "1.0", optional = true, default-features = false }

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

rustc-internal-api = []
rustc-dep-of-std = ["nightly", "core", "compiler_builtins", "alloc", "rustc-internal-api"]
rustc-dep-of-std = [
"nightly",
"core",
"compiler_builtins",
"alloc",
"rustc-internal-api",
]
raw = []

# Enables usage of `#[inline]` on far more functions than by default in this
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ pub mod hash_set {
pub use crate::map::HashMap;
pub use crate::set::HashSet;

#[cfg(feature = "equivalent")]
use equivalent::Equivalent;

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

#[cfg(not(feature = "equivalent"))]
impl<Q: ?Sized, K: ?Sized> Equivalent<K> for Q
where
Q: Eq,
Expand Down

0 comments on commit 3b348ea

Please sign in to comment.