Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Made dyn Array and Scalar PartialEq
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Dec 13, 2021
1 parent 89921d3 commit 9918726
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
18 changes: 15 additions & 3 deletions src/array/equal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ mod struct_;
mod union;
mod utf8;

impl PartialEq for dyn Array {
fn eq(&self, other: &Self) -> bool {
equal(self, other)
impl PartialEq for dyn Array + '_ {
fn eq(&self, that: &dyn Array) -> bool {
equal(self, that)
}
}

impl PartialEq<dyn Array> for Arc<dyn Array + '_> {
fn eq(&self, that: &dyn Array) -> bool {
equal(&**self, that)
}
}

impl PartialEq<dyn Array> for Box<dyn Array + '_> {
fn eq(&self, that: &dyn Array) -> bool {
equal(&**self, that)
}
}

Expand Down
20 changes: 17 additions & 3 deletions src/scalar/equal.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
use std::sync::Arc;

use super::*;
use crate::types::days_ms;

impl PartialEq for dyn Scalar {
fn eq(&self, other: &Self) -> bool {
equal(self, other)
impl PartialEq for dyn Scalar + '_ {
fn eq(&self, that: &dyn Scalar) -> bool {
equal(self, that)
}
}

impl PartialEq<dyn Scalar> for Arc<dyn Scalar + '_> {
fn eq(&self, that: &dyn Scalar) -> bool {
equal(&**self, that)
}
}

impl PartialEq<dyn Scalar> for Box<dyn Scalar + '_> {
fn eq(&self, that: &dyn Scalar) -> bool {
equal(&**self, that)
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/it/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,9 @@ fn test_with_validity() {
let expected = PrimitiveArray::from(&[Some(1i32), None, Some(3)]);
assert_eq!(arr_ref, &expected);
}

// check that `PartialEq` can be derived
#[derive(PartialEq)]
struct A {
array: std::sync::Arc<dyn Array>,
}
6 changes: 6 additions & 0 deletions tests/it/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ mod null;
mod primitive;
mod struct_;
mod utf8;

// check that `PartialEq` can be derived
#[derive(PartialEq)]
struct A {
array: std::sync::Arc<dyn arrow2::scalar::Scalar>,
}

0 comments on commit 9918726

Please sign in to comment.