From 6f5c9c0f8e13a0ab09e5052db80bfc791f83bb43 Mon Sep 17 00:00:00 2001 From: "S.Brandeis" Date: Sun, 19 Jan 2020 03:02:05 +0100 Subject: [PATCH] Broader PartialEq implementation for types implementing Dim trait --- src/base/dimension.rs | 45 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/base/dimension.rs b/src/base/dimension.rs index 5d1d1bd9..cabd8a1c 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -14,7 +14,7 @@ use typenum::{ use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// Dim of dynamically-sized algebraic entities. -#[derive(Clone, Copy, Eq, PartialEq, Debug)] +#[derive(Clone, Copy, Eq, Debug)] pub struct Dynamic { value: usize, } @@ -107,6 +107,12 @@ impl Sub for Dynamic { } } +impl PartialEq for Dynamic { + fn eq(&self, other: &T) -> bool { + self.value() == other.value() + } +} + /* * * Operations. @@ -244,7 +250,7 @@ impl NamedDim for typenum::U1 { macro_rules! named_dimension( ($($D: ident),* $(,)*) => {$( /// A type level dimension. - #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] + #[derive(Debug, Copy, Clone, Hash, Eq)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] pub struct $D; @@ -280,6 +286,12 @@ macro_rules! named_dimension( } impl IsNotStaticOne for $D { } + + impl PartialEq for $D { + fn eq(&self, other: &T) -> bool { + self.value() == other.value() + } + } )*} ); @@ -367,6 +379,23 @@ impl< { } +impl< + T: Dim, + A: Bit + Any + Debug + Copy + PartialEq + Send + Sync, + B: Bit + Any + Debug + Copy + PartialEq + Send + Sync, + C: Bit + Any + Debug + Copy + PartialEq + Send + Sync, + D: Bit + Any + Debug + Copy + PartialEq + Send + Sync, + E: Bit + Any + Debug + Copy + PartialEq + Send + Sync, + F: Bit + Any + Debug + Copy + PartialEq + Send + Sync, + G: Bit + Any + Debug + Copy + PartialEq + Send + Sync, + > PartialEq + for UInt, A>, B>, C>, D>, E>, F>, G> +{ + fn eq(&self, other: &T) -> bool { + self.value() == other.value() + } +} + impl NamedDim for UInt { @@ -408,3 +437,15 @@ impl { } + +impl< + T: Dim, + U: Unsigned + DimName, + B: Bit + Any + Debug + Copy + PartialEq + Send + Sync + > PartialEq + for UInt +{ + fn eq(&self, other: &T) -> bool { + self.value() == other.value() + } +}