From 6d83bc1902b95758d98ea973778d8fc4b4a599a2 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 6 Jun 2023 15:49:05 -0700 Subject: [PATCH] pub use equivalent::Equivalent; --- Cargo.toml | 2 ++ src/equivalent.rs | 27 --------------------------- src/lib.rs | 3 +-- src/map.rs | 3 +-- src/map/core.rs | 3 +-- 5 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 src/equivalent.rs diff --git a/Cargo.toml b/Cargo.toml index 22aa12ae..c2443c48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,8 @@ rust-version = "1.64" bench = false [dependencies] +equivalent = { version = "1.0", default-features = false } + arbitrary = { version = "1.0", optional = true, default-features = false } quickcheck = { version = "1.0", optional = true, default-features = false } serde = { version = "1.0", optional = true, default-features = false } diff --git a/src/equivalent.rs b/src/equivalent.rs deleted file mode 100644 index ad6635ff..00000000 --- a/src/equivalent.rs +++ /dev/null @@ -1,27 +0,0 @@ -use core::borrow::Borrow; - -/// Key equivalence trait. -/// -/// This trait allows hash table lookup to be customized. -/// It has one blanket implementation that uses the regular `Borrow` solution, -/// just like `HashMap` and `BTreeMap` do, so that you can pass `&str` to lookup -/// into a map with `String` keys and so on. -/// -/// # Contract -/// -/// The implementor **must** hash like `K`, if it is hashable. -pub trait Equivalent { - /// Compare self to `key` and return `true` if they are equal. - fn equivalent(&self, key: &K) -> bool; -} - -impl Equivalent for Q -where - Q: Eq, - K: Borrow, -{ - #[inline] - fn equivalent(&self, key: &K) -> bool { - *self == *key.borrow() - } -} diff --git a/src/lib.rs b/src/lib.rs index 2faf49e2..8939d261 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,7 +117,6 @@ use alloc::vec::{self, Vec}; mod arbitrary; #[macro_use] mod macros; -mod equivalent; mod mutable_keys; #[cfg(feature = "serde")] #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] @@ -136,9 +135,9 @@ mod rayon; #[cfg(feature = "rustc-rayon")] mod rustc; -pub use crate::equivalent::Equivalent; pub use crate::map::IndexMap; pub use crate::set::IndexSet; +pub use equivalent::Equivalent; // shared private items diff --git a/src/map.rs b/src/map.rs index c3b7e0bb..cd03ae8a 100644 --- a/src/map.rs +++ b/src/map.rs @@ -33,9 +33,8 @@ use alloc::vec::Vec; use std::collections::hash_map::RandomState; use self::core::IndexMapCore; -use crate::equivalent::Equivalent; use crate::util::{third, try_simplify_range}; -use crate::{Bucket, Entries, HashValue, TryReserveError}; +use crate::{Bucket, Entries, Equivalent, HashValue, TryReserveError}; /// A hash table where the iteration order of the key-value pairs is independent /// of the hash values of the keys. diff --git a/src/map/core.rs b/src/map/core.rs index c918deac..3e392ace 100644 --- a/src/map/core.rs +++ b/src/map/core.rs @@ -17,9 +17,8 @@ use core::fmt; use core::mem; use core::ops::RangeBounds; -use crate::equivalent::Equivalent; use crate::util::simplify_range; -use crate::{Bucket, Entries, HashValue}; +use crate::{Bucket, Entries, Equivalent, HashValue}; /// Core of the map that does not depend on S pub(crate) struct IndexMapCore {