From 61e4ada5e8a71d84c53b45527f97ad40bf24e7e6 Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Fri, 30 Jan 2015 12:12:41 -0800 Subject: [PATCH 1/2] Implementing equality operator for AzColor and Color objects. --- src/azure.rs | 10 ++++++++++ src/azure_hl.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/azure.rs b/src/azure.rs index f2187c6..f70f54e 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -253,6 +253,16 @@ pub struct struct__AzColor { pub type AzColor = struct__AzColor; +#[inline] +impl PartialEq for AzColor { + fn eq(&self, other: &AzColor) -> bool { + if self.r != other.r || self.g != other.g || self.b != other.b || self.a != other.a { + return false; + } + return true; + } +} + #[repr(C)] pub struct struct__AzGradientStop { pub offset: AzFloat, diff --git a/src/azure_hl.rs b/src/azure_hl.rs index 4d9723d..2f9bc52 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -125,6 +125,16 @@ impl Color { } } +#[inline] +impl PartialEq for Color { + fn eq(&self, other: &Color) -> bool { + if self.r != other.r || self.g != other.g || self.b != other.b || self.a != other.a { + return false; + } + return true; + } +} + // FIXME: Should have a class hierarchy here starting with Pattern. pub struct ColorPattern { From a90c5349f149cb7d1598295b68b024a4f89b6b8f Mon Sep 17 00:00:00 2001 From: Adenilson Cavalcanti Date: Fri, 30 Jan 2015 12:32:06 -0800 Subject: [PATCH 2/2] Streamlining the equality test (addresses reviewer's suggestion). --- src/azure.rs | 5 +---- src/azure_hl.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/azure.rs b/src/azure.rs index f70f54e..a31b1ea 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -256,10 +256,7 @@ pub type AzColor = struct__AzColor; #[inline] impl PartialEq for AzColor { fn eq(&self, other: &AzColor) -> bool { - if self.r != other.r || self.g != other.g || self.b != other.b || self.a != other.a { - return false; - } - return true; + self.r == other.r && self.g == other.g && self.b == other.b && self.a == other.a } } diff --git a/src/azure_hl.rs b/src/azure_hl.rs index 2f9bc52..52c8140 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -128,10 +128,7 @@ impl Color { #[inline] impl PartialEq for Color { fn eq(&self, other: &Color) -> bool { - if self.r != other.r || self.g != other.g || self.b != other.b || self.a != other.a { - return false; - } - return true; + self.r == other.r && self.g == other.g && self.b == other.b && self.a == other.a } }