Skip to content

Commit 34c5807

Browse files
committed
impl PartialEq for arrays too
(cherry picked from commit 6a83883)
1 parent 94118d1 commit 34c5807

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
@@ -351,6 +351,22 @@ impl<K: PartialEq, V: PartialEq> PartialEq<Slice<K, V>> for [(K, V)] {
351351
}
352352
}
353353

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)))
359+
}
360+
}
361+
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)
367+
}
368+
}
369+
354370
impl<K: Eq, V: Eq> Eq for Slice<K, V> {}
355371

356372
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
@@ -237,6 +237,18 @@ impl<T: PartialEq> PartialEq<Slice<T>> for [T] {
237237
}
238238
}
239239

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

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

0 commit comments

Comments
 (0)