Skip to content

Commit cf9397f

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
1 parent e5723e4 commit cf9397f

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
@@ -341,6 +341,22 @@ impl<K: PartialEq, V: PartialEq> PartialEq for Slice<K, V> {
341341
}
342342
}
343343

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)))
349+
}
350+
}
351+
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)
357+
}
358+
}
359+
344360
impl<K: Eq, V: Eq> Eq for Slice<K, V> {}
345361

346362
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
@@ -228,6 +228,18 @@ impl<T: PartialEq> PartialEq for Slice<T> {
228228
}
229229
}
230230

231+
impl<T: PartialEq> PartialEq<[T]> for Slice<T> {
232+
fn eq(&self, other: &[T]) -> bool {
233+
self.len() == other.len() && self.iter().eq(other)
234+
}
235+
}
236+
237+
impl<T: PartialEq> PartialEq<Slice<T>> for [T] {
238+
fn eq(&self, other: &Slice<T>) -> bool {
239+
self.len() == other.len() && self.iter().eq(other)
240+
}
241+
}
242+
231243
impl<T: Eq> Eq for Slice<T> {}
232244

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

0 commit comments

Comments
 (0)