From 08a8db9a3f9efd356a440c9af64b1e5c84bc4e11 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Mon, 20 Jan 2020 18:48:18 -0700 Subject: [PATCH] add Hash to ArrayVec and TinyVec --- src/arrayvec.rs | 17 ++++------------- src/lib.rs | 1 + src/tinyvec.rs | 17 ++++------------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/arrayvec.rs b/src/arrayvec.rs index f665498..5c75b14 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -918,24 +918,15 @@ where } } -/* - -I think, in retrospect, this is useless? - -The `&mut [A::Item]` should coerce to `&[A::Item]` and use the above impl. -I'll leave it here for now though since we already had it written out.. - -impl PartialEq<&mut [A::Item]> for ArrayVec +impl Hash for ArrayVec where - A::Item: PartialEq, + A::Item: Hash, { #[inline] - #[must_use] - fn eq(&self, other: &&mut [A::Item]) -> bool { - self.deref() == *other + fn hash(&self, state: &mut H) { + self.as_slice().hash(state) } } -*/ // // // Formatting impls diff --git a/src/lib.rs b/src/lib.rs index bb19bd2..12888a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,6 +66,7 @@ use core::{ Binary, Debug, Display, Formatter, LowerExp, LowerHex, Octal, Pointer, UpperExp, UpperHex, }, + hash::{Hash, Hasher}, iter::{Extend, FromIterator, IntoIterator, Iterator}, mem::{needs_drop, replace}, ops::{Deref, DerefMut, Index, IndexMut, RangeBounds}, diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 2ff42c8..ab4e5e4 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -792,24 +792,15 @@ where } } -/* - -I think, in retrospect, this is useless? - -The `&mut [A::Item]` should coerce to `&[A::Item]` and use the above impl. -I'll leave it here for now though since we already had it written out.. - -impl PartialEq<&mut [A::Item]> for TinyVec +impl Hash for TinyVec where - A::Item: PartialEq, + A::Item: Hash, { #[inline] - #[must_use] - fn eq(&self, other: &&mut [A::Item]) -> bool { - self.deref() == *other + fn hash(&self, state: &mut H) { + self.as_slice().hash(state) } } -*/ // // // Formatting impls