Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the Equivalent trait from the equivalent crate #442

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be pub to match the API without the feature?
(or else hide them both in a breaking change)


// 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
Loading