Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 105 additions & 3 deletions src/arraytraits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ where

/// Return `true` if the array shapes and all elements of `self` and
/// `rhs` are equal. Return `false` otherwise.
#[allow(clippy::unconditional_recursion)] // false positive
impl<A, B, S, S2, D> PartialEq<&ArrayBase<S2, D>> for ArrayBase<S, D>
where
A: PartialEq<B>,
Expand All @@ -223,7 +222,6 @@ where

/// Return `true` if the array shapes and all elements of `self` and
/// `rhs` are equal. Return `false` otherwise.
#[allow(clippy::unconditional_recursion)] // false positive
impl<A, B, S, S2, D> PartialEq<ArrayBase<S2, D>> for &ArrayBase<S, D>
where
A: PartialEq<B>,
Expand All @@ -236,7 +234,6 @@ where
**self == *rhs
}
}

impl<S, D> Eq for ArrayBase<S, D>
where
D: Dimension,
Expand All @@ -245,6 +242,78 @@ where
{
}

impl<A, B, S, D> PartialEq<ArrayRef<B, D>> for ArrayBase<S, D>
where
S: Data<Elem = A>,
A: PartialEq<B>,
D: Dimension,
{
fn eq(&self, other: &ArrayRef<B, D>) -> bool
{
**self == other
}
}

impl<A, B, S, D> PartialEq<&ArrayRef<B, D>> for ArrayBase<S, D>
where
S: Data<Elem = A>,
A: PartialEq<B>,
D: Dimension,
{
fn eq(&self, other: &&ArrayRef<B, D>) -> bool
{
**self == *other
}
}

impl<A, B, S, D> PartialEq<ArrayRef<B, D>> for &ArrayBase<S, D>
where
S: Data<Elem = A>,
A: PartialEq<B>,
D: Dimension,
{
fn eq(&self, other: &ArrayRef<B, D>) -> bool
{
**self == other
}
}

impl<A, B, S, D> PartialEq<ArrayBase<S, D>> for ArrayRef<A, D>
where
S: Data<Elem = B>,
A: PartialEq<B>,
D: Dimension,
{
fn eq(&self, other: &ArrayBase<S, D>) -> bool
{
self == **other
}
}

impl<A, B, S, D> PartialEq<&ArrayBase<S, D>> for ArrayRef<A, D>
where
S: Data<Elem = B>,
A: PartialEq<B>,
D: Dimension,
{
fn eq(&self, other: &&ArrayBase<S, D>) -> bool
{
self == ***other
}
}

impl<A, B, S, D> PartialEq<ArrayBase<S, D>> for &ArrayRef<A, D>
where
S: Data<Elem = B>,
A: PartialEq<B>,
D: Dimension,
{
fn eq(&self, other: &ArrayBase<S, D>) -> bool
{
*self == **other
}
}

impl<A, S> From<Box<[A]>> for ArrayBase<S, Ix1>
where S: DataOwned<Elem = A>
{
Expand Down Expand Up @@ -643,3 +712,36 @@ where
ArrayBase::default(D::default())
}
}

#[cfg(test)]
mod tests
{
use crate::array;

#[test]
fn test_eq_traits()
{
let a = array![1, 2, 3];
let a_ref = &*a;
let b = array![1, 2, 3];
let b_ref = &*b;

assert_eq!(a, b);
assert_eq!(a, &b);
assert_eq!(&a, b);
assert_eq!(&a, &b);

assert_eq!(a_ref, b_ref);
assert_eq!(&a_ref, b_ref);
assert_eq!(a_ref, &b_ref);
assert_eq!(&a_ref, &b_ref);

assert_eq!(a_ref, b);
assert_eq!(a_ref, &b);
assert_eq!(&a_ref, &b);

assert_eq!(a, b_ref);
assert_eq!(&a, b_ref);
assert_eq!(&a, &b_ref);
}
}
Loading