Skip to content

Commit 6a83883

Browse files
committed
impl PartialEq for arrays too
1 parent cf9397f commit 6a83883

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/map/slice.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,22 @@ impl<K: PartialEq, V: PartialEq> PartialEq<Slice<K, V>> for [(K, V)] {
357357
}
358358
}
359359

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)))
365+
}
366+
}
367+
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)
373+
}
374+
}
375+
360376
impl<K: Eq, V: Eq> Eq for Slice<K, V> {}
361377

362378
impl<K: PartialOrd, V: PartialOrd> PartialOrd for Slice<K, V> {

src/set/slice.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ impl<T: PartialEq> PartialEq<Slice<T>> for [T] {
240240
}
241241
}
242242

243+
impl<T: PartialEq, const N: usize> PartialEq<[T; N]> for Slice<T> {
244+
fn eq(&self, other: &[T; N]) -> bool {
245+
self.len() == N && self.iter().eq(other)
246+
}
247+
}
248+
249+
impl<T: PartialEq, const N: usize> PartialEq<Slice<T>> for [T; N] {
250+
fn eq(&self, other: &Slice<T>) -> bool {
251+
N == other.len() && self.iter().eq(other)
252+
}
253+
}
254+
243255
impl<T: Eq> Eq for Slice<T> {}
244256

245257
impl<T: PartialOrd> PartialOrd for Slice<T> {

0 commit comments

Comments
 (0)