From 23e21ac1b3df00ac41b41a63936acbc3e6640acb Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 9 Jul 2013 23:10:59 +1000 Subject: [PATCH] Improve trait bounds --- src/color/hsv.rs | 24 ++++++++++++------------ src/color/rgb.rs | 16 ++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/color/hsv.rs b/src/color/hsv.rs index a415cc0..ce8b570 100644 --- a/src/color/hsv.rs +++ b/src/color/hsv.rs @@ -25,27 +25,27 @@ mod num_macros; #[deriving(Clone, Eq)] pub struct HSV { h: T, s: T, v: T } -impl HSV { +impl HSV { pub fn new(h: T, s: T, v: T) -> HSV { HSV { h: h, s: s, v: v } } } pub trait ToHSV { - pub fn to_hsv(&self) -> HSV; + pub fn to_hsv(&self) -> HSV; } -impl ToHSV for HSV { +impl ToHSV for HSV { #[inline] - pub fn to_hsv(&self) -> HSV { + pub fn to_hsv(&self) -> HSV { HSV::new(Channel::from((*self).h.clone()), Channel::from((*self).s.clone()), Channel::from((*self).v.clone())) } } -impl ToRGB for HSV { - pub fn to_rgb(&self) -> RGB { +impl ToRGB for HSV { + pub fn to_rgb(&self) -> RGB { // Algorithm taken from the Wikipedia article on HSL and HSV: // http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV @@ -79,7 +79,7 @@ impl ToRGB for HSV { #[deriving(Clone, Eq)] pub struct HSVA { h: T, s: T, v: T, a: T } -impl HSVA { +impl HSVA { #[inline] pub fn new(h: T, s: T, v: T, a: T) -> HSVA { HSVA { h: h, s: s, v: v, a: a } @@ -102,12 +102,12 @@ impl HSVA { } pub trait ToHSVA { - pub fn to_hsva(&self) -> HSVA; + pub fn to_hsva(&self) -> HSVA; } -impl ToHSVA for (C, T) { +impl ToHSVA for (C, T) { #[inline] - pub fn to_hsva(&self) -> HSVA { + pub fn to_hsva(&self) -> HSVA { match *self { (ref hsv, ref a) => { HSVA::from_hsv_a( @@ -119,9 +119,9 @@ impl ToHSVA for (C, T) { } } -impl ToRGBA for HSVA { +impl ToRGBA for HSVA { #[inline] - pub fn to_rgba(&self) -> RGBA { + pub fn to_rgba(&self) -> RGBA { RGBA::from_rgb_a( self.hsv().to_rgb(), Channel::from((*self).a.clone()) diff --git a/src/color/rgb.rs b/src/color/rgb.rs index 90dff74..74b35ca 100644 --- a/src/color/rgb.rs +++ b/src/color/rgb.rs @@ -25,7 +25,7 @@ mod num_macros; #[deriving(Clone, Eq)] pub struct RGB { r: T, g: T, b: T } -impl RGB { +impl RGB { #[inline] pub fn new(r: T, g: T, b: T) -> RGB { RGB { r: r, g: g, b: b } @@ -33,12 +33,12 @@ impl RGB { } pub trait ToRGB { - pub fn to_rgb(&self) -> RGB; + pub fn to_rgb(&self) -> RGB; } impl ToRGB for RGB { #[inline] - pub fn to_rgb(&self) -> RGB { + pub fn to_rgb(&self) -> RGB { RGB::new(Channel::from((*self).r.clone()), Channel::from((*self).g.clone()), Channel::from((*self).b.clone())) @@ -47,7 +47,7 @@ impl ToRGB for RGB { impl ToHSV for RGB { #[inline] - pub fn to_hsv(&self) -> HSV { + pub fn to_hsv(&self) -> HSV { // Algorithm taken from the Wikipedia article on HSL and HSV: // http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV @@ -77,7 +77,7 @@ impl ToHSV for RGB { #[deriving(Clone, Eq)] pub struct RGBA { r: T, g: T, b: T, a: T } -impl RGBA { +impl RGBA { #[inline] pub fn new(r: T, g: T, b: T, a: T) -> RGBA { RGBA { r: r, g: g, b: b, a: a } @@ -100,12 +100,12 @@ impl RGBA { } pub trait ToRGBA { - pub fn to_rgba(&self) -> RGBA; + pub fn to_rgba(&self) -> RGBA; } impl ToRGBA for (C, T) { #[inline] - pub fn to_rgba(&self) -> RGBA { + pub fn to_rgba(&self) -> RGBA { match *self { (ref rgb, ref a) => { RGBA::from_rgb_a(rgb.to_rgb(), Channel::from(a.clone())) @@ -116,7 +116,7 @@ impl ToRGBA for (C, T) { impl ToHSVA for RGBA { #[inline] - pub fn to_hsva(&self) -> HSVA { + pub fn to_hsva(&self) -> HSVA { HSVA::from_hsv_a( self.rgb().to_hsv(), Channel::from((*self).a.clone())