@@ -2,7 +2,7 @@ use super::{
22 Bucket , Entries , IndexMap , IntoIter , IntoKeys , IntoValues , Iter , IterMut , Keys , Values ,
33 ValuesMut ,
44} ;
5- use crate :: util:: try_simplify_range;
5+ use crate :: util:: { slice_eq , try_simplify_range} ;
66
77use alloc:: boxed:: Box ;
88use alloc:: vec:: Vec ;
@@ -335,9 +335,55 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Slice<K, V> {
335335 }
336336}
337337
338- impl < K : PartialEq , V : PartialEq > PartialEq for Slice < K , V > {
339- fn eq ( & self , other : & Self ) -> bool {
340- self . len ( ) == other. len ( ) && self . iter ( ) . eq ( other)
338+ impl < K , V , K2 , V2 > PartialEq < Slice < K2 , V2 > > for Slice < K , V >
339+ where
340+ K : PartialEq < K2 > ,
341+ V : PartialEq < V2 > ,
342+ {
343+ fn eq ( & self , other : & Slice < K2 , V2 > ) -> bool {
344+ slice_eq ( & self . entries , & other. entries , |b1, b2| {
345+ b1. key == b2. key && b1. value == b2. value
346+ } )
347+ }
348+ }
349+
350+ impl < K , V , K2 , V2 > PartialEq < [ ( K2 , V2 ) ] > for Slice < K , V >
351+ where
352+ K : PartialEq < K2 > ,
353+ V : PartialEq < V2 > ,
354+ {
355+ fn eq ( & self , other : & [ ( K2 , V2 ) ] ) -> bool {
356+ slice_eq ( & self . entries , other, |b, t| b. key == t. 0 && b. value == t. 1 )
357+ }
358+ }
359+
360+ impl < K , V , K2 , V2 > PartialEq < Slice < K2 , V2 > > for [ ( K , V ) ]
361+ where
362+ K : PartialEq < K2 > ,
363+ V : PartialEq < V2 > ,
364+ {
365+ fn eq ( & self , other : & Slice < K2 , V2 > ) -> bool {
366+ slice_eq ( self , & other. entries , |t, b| t. 0 == b. key && t. 1 == b. value )
367+ }
368+ }
369+
370+ impl < K , V , K2 , V2 , const N : usize > PartialEq < [ ( K2 , V2 ) ; N ] > for Slice < K , V >
371+ where
372+ K : PartialEq < K2 > ,
373+ V : PartialEq < V2 > ,
374+ {
375+ fn eq ( & self , other : & [ ( K2 , V2 ) ; N ] ) -> bool {
376+ <Self as PartialEq < [ _ ] > >:: eq ( self , other)
377+ }
378+ }
379+
380+ impl < K , V , const N : usize , K2 , V2 > PartialEq < Slice < K2 , V2 > > for [ ( K , V ) ; N ]
381+ where
382+ K : PartialEq < K2 > ,
383+ V : PartialEq < V2 > ,
384+ {
385+ fn eq ( & self , other : & Slice < K2 , V2 > ) -> bool {
386+ <[ _ ] as PartialEq < _ > >:: eq ( self , other)
341387 }
342388}
343389
0 commit comments