@@ -36,11 +36,11 @@ impl FromStr for RGBColor {
3636
3737 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
3838 if s. starts_with ( '#' ) {
39- return RGBColor :: from_hex_str ( s) ;
39+ RGBColor :: from_hex_str ( s)
4040 } else if s. contains ( ',' ) {
41- return RGBColor :: from_rgb_str ( s) ;
41+ RGBColor :: from_rgb_str ( s)
4242 } else {
43- return RGBColor :: from_named_color ( s) ;
43+ RGBColor :: from_named_color ( s)
4444 }
4545 }
4646}
@@ -60,9 +60,9 @@ impl RGBColor {
6060 let parts: Vec < & str > = s. split ( ',' ) . map ( |part| part. trim ( ) ) . collect ( ) ;
6161 if parts. len ( ) == 3 {
6262 if let ( Ok ( r) , Ok ( g) , Ok ( b) ) = ( parts[ 0 ] . parse ( ) , parts[ 1 ] . parse ( ) , parts[ 2 ] . parse ( ) ) {
63- return Ok ( Self ( r, g, b) ) ;
63+ Ok ( Self ( r, g, b) )
6464 } else {
65- return Err ( ParseErrorKind :: InvalidFormat ( s. to_string ( ) ) ) ;
65+ Err ( ParseErrorKind :: InvalidFormat ( s. to_string ( ) ) )
6666 }
6767 } else {
6868 Err ( ParseErrorKind :: InvalidFormat ( s. to_string ( ) ) )
@@ -90,9 +90,9 @@ impl std::ops::Mul<f32> for RGBColor {
9090
9191 fn mul ( self , rhs : f32 ) -> Self :: Output {
9292 RGBColor (
93- ( self . r ( ) as f32 * rhs) . min ( 255.0 ) . max ( 0 .0) as u8 ,
94- ( self . g ( ) as f32 * rhs) . min ( 255.0 ) . max ( 0 .0) as u8 ,
95- ( self . b ( ) as f32 * rhs) . min ( 255.0 ) . max ( 0 .0) as u8 ,
93+ ( self . r ( ) as f32 * rhs) . clamp ( 0.0 , 255 .0) as u8 ,
94+ ( self . g ( ) as f32 * rhs) . clamp ( 0.0 , 255 .0) as u8 ,
95+ ( self . b ( ) as f32 * rhs) . clamp ( 0.0 , 255 .0) as u8 ,
9696 )
9797 }
9898}
@@ -106,6 +106,7 @@ pub struct LinearGradient {
106106 end : RGBColor ,
107107}
108108
109+ #[ allow( dead_code) ]
109110pub struct LinearGradientSteps < ' a > {
110111 gradient : & ' a LinearGradient ,
111112 current : usize ,
@@ -143,7 +144,7 @@ impl LinearGradient {
143144 /// Interpolate between two colors. The factor has to be between 0 and 1
144145 pub fn interpolate ( & self , factor : f32 ) -> RGBColor {
145146 assert ! (
146- factor >= 0.0 && factor <= 1.0 ,
147+ ( 0.0 ..= 1.0 ) . contains ( & factor ) ,
147148 "The factor value must be between 0 and 1"
148149 ) ;
149150 let delta = self . delta ( ) ;
@@ -225,10 +226,8 @@ mod tests {
225226 assert_eq ! ( RGBColor :: from_hex_str( "#00FF00" ) , Ok ( RGBColor ( 0 , 255 , 0 ) ) ) ;
226227 assert_eq ! ( RGBColor :: from_hex_str( "#0000FF" ) , Ok ( RGBColor ( 0 , 0 , 255 ) ) ) ;
227228 assert ! (
228- RGBColor :: from_hex_str( "#GGGGGG" ) . is_err_and( |x| match x {
229- ParseErrorKind :: InvalidHexValue ( _) => true ,
230- _ => false ,
231- } ) ,
229+ RGBColor :: from_hex_str( "#GGGGGG" )
230+ . is_err_and( |x| { matches!( x, ParseErrorKind :: InvalidHexValue ( _) ) } ) ,
232231 "Invalid Hex Format"
233232 )
234233 }
0 commit comments