From 79c848c590a71702342dcc18300f00718461c854 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 10 Jun 2018 16:04:47 +0200 Subject: [PATCH] Make ConvertInto wrap ConvertFrom for convert_unclamped --- palette/src/convert.rs | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/palette/src/convert.rs b/palette/src/convert.rs index 5e8bf927b..29b055ae0 100644 --- a/palette/src/convert.rs +++ b/palette/src/convert.rs @@ -534,8 +534,6 @@ impl Display for OutOfBounds { } ///A trait for converting a color into another. -/// -///`convert_unclamped` currently wraps the underlying `Into` implementation. pub trait ConvertInto: Into { ///Convert into T with values clamped to the color defined bounds /// @@ -561,9 +559,7 @@ pub trait ConvertInto: Into { ///assert!(!rgb.is_valid()); ///``` #[inline] - fn convert_unclamped_into(self) -> T { - self.into() - } + fn convert_unclamped_into(self) -> T; ///Convert into T, returning ok if the color is inside of its defined range, ///otherwise an `OutOfBounds` error is returned which contains the unclamped color. @@ -585,7 +581,7 @@ pub trait ConvertInto: Into { ///A trait for converting one color from another. /// -///`convert_unclamped` currently wraps the underlying `Into` implementation. +///`convert_unclamped` currently wraps the underlying `From` implementation. pub trait ConvertFrom: From { ///Convert from T with values clamped to the color defined bounds /// @@ -659,24 +655,17 @@ impl ConvertInto for T where U: ConvertFrom { U::convert_from(self) } + #[inline] + fn convert_unclamped_into(self) -> U { + U::convert_unclamped_from(self) + } + #[inline] fn try_convert_into(self) -> Result> { U::try_convert_from(self) } } -/* -impl_convert!(impl Rgb); -impl_convert!(impl Luma); -impl_convert!(float_component impl Hsl); -impl_convert!(float_component impl Hsv); -impl_convert!(float_component impl Hwb); -impl_convert!(float_component impl Lab); -impl_convert!(float_component impl Lch); -impl_convert!(float_component impl Xyz); -impl_convert!(float_component impl Yxy); -*/ - macro_rules! impl_into_color { ($self_ty: ident, $from_fn: ident) => { impl IntoColor for $self_ty