Skip to content

Commit 94118d1

Browse files
committed
impl PartialEq between Slice and []
```rust impl<K: PartialEq, V: PartialEq> PartialEq<[(K, V)]> for map::Slice<K, V> {...} impl<K: PartialEq, V: PartialEq> PartialEq<map::Slice<K, V>> for [(K, V)] {...} impl<T: PartialEq> PartialEq<[T]> for set::Slice<T> {...} impl<T: PartialEq> PartialEq<set::Slice<T>> for [T] {...} ``` Resolves #375 (cherry picked from commit cf9397f)
1 parent 3bd4ab3 commit 94118d1

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
@@ -335,6 +335,22 @@ impl<K: PartialEq, V: PartialEq> PartialEq for Slice<K, V> {
335335
}
336336
}
337337

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)))
343+
}
344+
}
345+
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)
351+
}
352+
}
353+
338354
impl<K: Eq, V: Eq> Eq for Slice<K, V> {}
339355

340356
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
@@ -225,6 +225,18 @@ impl<T: PartialEq> PartialEq for Slice<T> {
225225
}
226226
}
227227

228+
impl<T: PartialEq> PartialEq<[T]> for Slice<T> {
229+
fn eq(&self, other: &[T]) -> bool {
230+
self.len() == other.len() && self.iter().eq(other)
231+
}
232+
}
233+
234+
impl<T: PartialEq> PartialEq<Slice<T>> for [T] {
235+
fn eq(&self, other: &Slice<T>) -> bool {
236+
self.len() == other.len() && self.iter().eq(other)
237+
}
238+
}
239+
228240
impl<T: Eq> Eq for Slice<T> {}
229241

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

0 commit comments

Comments
 (0)