|
1 | 1 | use super::{Bucket, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, Values, ValuesMut}; |
2 | | -use crate::util::try_simplify_range; |
| 2 | +use crate::util::{slice_eq, try_simplify_range}; |
3 | 3 |
|
4 | 4 | use alloc::boxed::Box; |
5 | 5 | use alloc::collections::VecDeque; |
@@ -329,41 +329,55 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for Slice<K, V> { |
329 | 329 | } |
330 | 330 | } |
331 | 331 |
|
332 | | -impl<K: PartialEq, V: PartialEq> PartialEq for Slice<K, V> { |
333 | | - fn eq(&self, other: &Self) -> bool { |
334 | | - self.len() == other.len() && self.iter().eq(other) |
| 332 | +impl<K, V, K2, V2> PartialEq<Slice<K2, V2>> for Slice<K, V> |
| 333 | +where |
| 334 | + K: PartialEq<K2>, |
| 335 | + V: PartialEq<V2>, |
| 336 | +{ |
| 337 | + fn eq(&self, other: &Slice<K2, V2>) -> bool { |
| 338 | + slice_eq(&self.entries, &other.entries, |b1, b2| { |
| 339 | + b1.key == b2.key && b1.value == b2.value |
| 340 | + }) |
335 | 341 | } |
336 | 342 | } |
337 | 343 |
|
338 | | -impl<K: PartialEq, V: PartialEq> PartialEq<[(K, V)]> for Slice<K, V> { |
339 | | - fn eq(&self, other: &[(K, V)]) -> bool { |
340 | | - self.len() == other.len() && |
341 | | - // mapping from `&(K, V)` to `(&K, &V)` |
342 | | - self.iter().eq(other.iter().map(|(k, v)| (k, v))) |
| 344 | +impl<K, V, K2, V2> PartialEq<[(K2, V2)]> for Slice<K, V> |
| 345 | +where |
| 346 | + K: PartialEq<K2>, |
| 347 | + V: PartialEq<V2>, |
| 348 | +{ |
| 349 | + fn eq(&self, other: &[(K2, V2)]) -> bool { |
| 350 | + slice_eq(&self.entries, other, |b, t| b.key == t.0 && b.value == t.1) |
343 | 351 | } |
344 | 352 | } |
345 | 353 |
|
346 | | -impl<K: PartialEq, V: PartialEq> PartialEq<Slice<K, V>> for [(K, V)] { |
347 | | - fn eq(&self, other: &Slice<K, V>) -> bool { |
348 | | - self.len() == other.len() && |
349 | | - // mapping from `&(K, V)` to `(&K, &V)` |
350 | | - self.iter().map(|(k, v)| (k, v)).eq(other) |
| 354 | +impl<K, V, K2, V2> PartialEq<Slice<K2, V2>> for [(K, V)] |
| 355 | +where |
| 356 | + K: PartialEq<K2>, |
| 357 | + V: PartialEq<V2>, |
| 358 | +{ |
| 359 | + fn eq(&self, other: &Slice<K2, V2>) -> bool { |
| 360 | + slice_eq(self, &other.entries, |t, b| t.0 == b.key && t.1 == b.value) |
351 | 361 | } |
352 | 362 | } |
353 | 363 |
|
354 | | -impl<K: PartialEq, V: PartialEq, const N: usize> PartialEq<[(K, V); N]> for Slice<K, V> { |
355 | | - fn eq(&self, other: &[(K, V); N]) -> bool { |
356 | | - self.len() == N && |
357 | | - // mapping from `&(K, V)` to `(&K, &V)` |
358 | | - self.iter().eq(other.iter().map(|(k, v)| (k, v))) |
| 364 | +impl<K, V, K2, V2, const N: usize> PartialEq<[(K2, V2); N]> for Slice<K, V> |
| 365 | +where |
| 366 | + K: PartialEq<K2>, |
| 367 | + V: PartialEq<V2>, |
| 368 | +{ |
| 369 | + fn eq(&self, other: &[(K2, V2); N]) -> bool { |
| 370 | + <Self as PartialEq<[_]>>::eq(self, other) |
359 | 371 | } |
360 | 372 | } |
361 | 373 |
|
362 | | -impl<K: PartialEq, V: PartialEq, const N: usize> PartialEq<Slice<K, V>> for [(K, V); N] { |
363 | | - fn eq(&self, other: &Slice<K, V>) -> bool { |
364 | | - N == other.len() && |
365 | | - // mapping from `&(K, V)` to `(&K, &V)` |
366 | | - self.iter().map(|(k, v)| (k, v)).eq(other) |
| 374 | +impl<K, V, const N: usize, K2, V2> PartialEq<Slice<K2, V2>> for [(K, V); N] |
| 375 | +where |
| 376 | + K: PartialEq<K2>, |
| 377 | + V: PartialEq<V2>, |
| 378 | +{ |
| 379 | + fn eq(&self, other: &Slice<K2, V2>) -> bool { |
| 380 | + <[_] as PartialEq<_>>::eq(self, other) |
367 | 381 | } |
368 | 382 | } |
369 | 383 |
|
|
0 commit comments