@@ -2,7 +2,7 @@ use super::{
2
2
Bucket , Entries , IndexMap , IntoIter , IntoKeys , IntoValues , Iter , IterMut , Keys , Values ,
3
3
ValuesMut ,
4
4
} ;
5
- use crate :: util:: try_simplify_range;
5
+ use crate :: util:: { slice_eq , try_simplify_range} ;
6
6
7
7
use alloc:: boxed:: Box ;
8
8
use alloc:: vec:: Vec ;
@@ -335,41 +335,55 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Slice<K, V> {
335
335
}
336
336
}
337
337
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
+ } )
341
347
}
342
348
}
343
349
344
- impl < K : PartialEq , V : PartialEq > PartialEq < [ ( K , V ) ] > for Slice < K , V > {
345
- fn eq ( & self , other : & [ ( K , V ) ] ) -> bool {
346
- self . len ( ) == other. len ( ) &&
347
- // mapping from `&(K, V)` to `(&K, &V)`
348
- self . iter ( ) . eq ( other. iter ( ) . map ( |( k, v) | ( k, v) ) )
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 )
349
357
}
350
358
}
351
359
352
- impl < K : PartialEq , V : PartialEq > PartialEq < Slice < K , V > > for [ ( K , V ) ] {
353
- fn eq ( & self , other : & Slice < K , V > ) -> bool {
354
- self . len ( ) == other. len ( ) &&
355
- // mapping from `&(K, V)` to `(&K, &V)`
356
- self . iter ( ) . map ( |( k, v) | ( k, v) ) . eq ( other)
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 )
357
367
}
358
368
}
359
369
360
- impl < K : PartialEq , V : PartialEq , const N : usize > PartialEq < [ ( K , V ) ; N ] > for Slice < K , V > {
361
- fn eq ( & self , other : & [ ( K , V ) ; N ] ) -> bool {
362
- self . len ( ) == N &&
363
- // mapping from `&(K, V)` to `(&K, &V)`
364
- self . iter ( ) . eq ( other. iter ( ) . map ( |( k, v) | ( k, v) ) )
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)
365
377
}
366
378
}
367
379
368
- impl < K : PartialEq , V : PartialEq , const N : usize > PartialEq < Slice < K , V > > for [ ( K , V ) ; N ] {
369
- fn eq ( & self , other : & Slice < K , V > ) -> bool {
370
- N == other. len ( ) &&
371
- // mapping from `&(K, V)` to `(&K, &V)`
372
- self . iter ( ) . map ( |( k, v) | ( k, v) ) . eq ( other)
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)
373
387
}
374
388
}
375
389
0 commit comments