@@ -3,7 +3,7 @@ use crate::util::OneWayOwned;
33use std:: fmt:: Display ;
44
55pub trait IntoColor < T > : Into < ColorType < T > > + Clone { }
6- impl < TC , T : ? Sized + Into < ColorType < TC > > + Clone > IntoColor < TC > for T { }
6+ impl < TC , T : Into < ColorType < TC > > + Clone > IntoColor < TC > for T { }
77
88pub type ColorIndex = u8 ;
99pub type ColorComponent = u8 ;
@@ -147,31 +147,30 @@ impl<T: Display> ColorType<T>
147147 . map ( |( r, g, b) | from_argb ( 0 , * r, * g, * b) as f64 )
148148 . collect ( ) ,
149149 VariableARGBInteger ( items) => items
150- . into_iter ( )
150+ . iter ( )
151151 . map ( |( a, r, g, b) | from_argb ( * a, * r, * g, * b) as f64 )
152152 . collect ( ) ,
153153 PaletteFracColor ( _) => panic ! ( "data() called on non-variable color type." ) ,
154154 PaletteCBColor ( _) => panic ! ( "data() called on non-variable color type." ) ,
155155 VariablePaletteColor ( items) => items. clone ( ) ,
156156 SavedColorMap ( _, items) => items. clone ( ) ,
157157 Index ( _) => panic ! ( "data() called on non-variable color type." ) ,
158- VariableIndex ( items) => items. into_iter ( ) . map ( |v| * v as f64 ) . collect ( ) ,
158+ VariableIndex ( items) => items. iter ( ) . map ( |v| * v as f64 ) . collect ( ) ,
159159 Background => panic ! ( "data() called on non-variable color type." ) ,
160160 Black => panic ! ( "data() called on non-variable color type." ) ,
161161 }
162162 }
163163
164164 pub fn is_variable ( & self ) -> bool
165165 {
166- match self
167- {
166+ matches ! (
167+ self ,
168168 VariableRGBInteger ( _)
169- | VariableARGBInteger ( _)
170- | VariableIndex ( _)
171- | VariablePaletteColor ( _)
172- | SavedColorMap ( _, _) => true ,
173- _ => false ,
174- }
169+ | VariableARGBInteger ( _)
170+ | VariableIndex ( _)
171+ | VariablePaletteColor ( _)
172+ | SavedColorMap ( _, _)
173+ )
175174 }
176175
177176 pub fn has_alpha ( & self ) -> bool
@@ -181,18 +180,8 @@ impl<T: Display> ColorType<T>
181180 RGBString ( s) =>
182181 {
183182 let s = s. to_string ( ) ;
184- if s. starts_with ( "0x" ) && s. chars ( ) . count ( ) == 10
185- {
186- true
187- }
188- else if s. starts_with ( "#" ) && s. chars ( ) . count ( ) == 9
189- {
190- true
191- }
192- else
193- {
194- false
195- }
183+ s. starts_with ( "0x" ) && s. chars ( ) . count ( ) == 10
184+ || s. starts_with ( "#" ) && s. chars ( ) . count ( ) == 9
196185 }
197186 ARGBInteger ( _, _, _, _) | VariableARGBInteger ( _) => true ,
198187 _ => false ,
@@ -208,7 +197,7 @@ fn from_argb(a: ColorComponent, r: ColorComponent, g: ColorComponent, b: ColorCo
208197
209198fn float_color_to_int ( v : f64 ) -> u8
210199{
211- if v < 0.0 || v > 1.0
200+ if ! ( 0.0 ..= 1.0 ) . contains ( & v )
212201 {
213202 panic ! (
214203 "Float value must be greater than zero and less than one. Actual value: {}" ,
@@ -260,106 +249,106 @@ pub fn floats_to_argb(a: f64, r: f64, g: f64, b: f64) -> ARGBInts
260249 )
261250}
262251
263- impl < ' l > Into < ColorType < String > > for & ' l str
252+ impl < ' l > From < & ' l str > for ColorType < String >
264253{
265254 /// Converts `&str` into [RGBString]
266- fn into ( self ) -> ColorType < String >
255+ fn from ( value : & ' l str ) -> Self
267256 {
268- ColorType :: RGBString ( String :: from ( self ) )
257+ ColorType :: RGBString ( String :: from ( value ) )
269258 }
270259}
271260
272- impl < ' l > Into < ColorType < String > > for String
261+ impl < ' l > From < String > for ColorType < String >
273262{
274263 /// Converts `String` into [RGBString]
275- fn into ( self ) -> ColorType < String >
264+ fn from ( value : String ) -> Self
276265 {
277- ColorType :: RGBString ( self )
266+ ColorType :: RGBString ( value )
278267 }
279268}
280269
281- impl < ' l > Into < ColorType < & ' l str > > for & ' l str
270+ impl < ' l > From < & ' l str > for ColorType < & ' l str >
282271{
283272 /// Converts `&str` into [RGBString]
284- fn into ( self ) -> ColorType < & ' l str >
273+ fn from ( value : & ' l str ) -> Self
285274 {
286- ColorType :: RGBString ( self )
275+ ColorType :: RGBString ( value )
287276 }
288277}
289278
290- impl < T > Into < ColorType < T > > for ARGBInts
279+ impl < T > From < ARGBInts > for ColorType < T >
291280{
292281 /// Converts `(u8, u8, u8, u8)` into [ARGBInteger]
293- fn into ( self ) -> ColorType < T >
282+ fn from ( value : ARGBInts ) -> Self
294283 {
295- ColorType :: ARGBInteger ( self . 0 , self . 1 , self . 2 , self . 3 )
284+ ColorType :: ARGBInteger ( value . 0 , value . 1 , value . 2 , value . 3 )
296285 }
297286}
298287
299- impl < T > Into < ColorType < T > > for RGBInts
288+ impl < T > From < RGBInts > for ColorType < T >
300289{
301290 /// Converts `(u8, u8, u8)` into [RGBInteger]
302- fn into ( self ) -> ColorType < T >
291+ fn from ( value : RGBInts ) -> Self
303292 {
304- ColorType :: RGBInteger ( self . 0 , self . 1 , self . 2 )
293+ ColorType :: RGBInteger ( value . 0 , value . 1 , value . 2 )
305294 }
306295}
307296
308- impl < T > Into < ColorType < T > > for ( f64 , f64 , f64 )
297+ impl < T > From < ( f64 , f64 , f64 ) > for ColorType < T >
309298{
310299 /// Converts `(f64, f64, f64)` into [RGBInteger].
311300 /// All values must be in the range 0-1, or the function will panic.
312- fn into ( self ) -> ColorType < T >
301+ fn from ( value : ( f64 , f64 , f64 ) ) -> Self
313302 {
314- let ints = floats_to_rgb ( self . 0 , self . 1 , self . 2 ) ;
303+ let ints = floats_to_rgb ( value . 0 , value . 1 , value . 2 ) ;
315304 ColorType :: RGBInteger ( ints. 0 , ints. 1 , ints. 2 )
316305 }
317306}
318307
319- impl < T > Into < ColorType < T > > for ( f64 , f64 , f64 , f64 )
308+ impl < T > From < ( f64 , f64 , f64 , f64 ) > for ColorType < T >
320309{
321310 /// Converts `(f64, f64, f64, f64)` into [ARGBInteger].
322311 /// All values must be in the range 0-1, or the function will panic.
323- fn into ( self ) -> ColorType < T >
312+ fn from ( value : ( f64 , f64 , f64 , f64 ) ) -> Self
324313 {
325- let ints = floats_to_argb ( self . 0 , self . 1 , self . 2 , self . 3 ) ;
314+ let ints = floats_to_argb ( value . 0 , value . 1 , value . 2 , value . 3 ) ;
326315 ColorType :: ARGBInteger ( ints. 0 , ints. 1 , ints. 2 , ints. 3 )
327316 }
328317}
329318
330- impl < T > Into < ColorType < T > > for Vec < RGBInts >
319+ impl < T > From < Vec < RGBInts > > for ColorType < T >
331320{
332321 /// Converts `Vec<(u8, u8, u8)>` into [VariableRGBInteger]
333- fn into ( self ) -> ColorType < T >
322+ fn from ( value : Vec < RGBInts > ) -> Self
334323 {
335- ColorType :: VariableRGBInteger ( self )
324+ ColorType :: VariableRGBInteger ( value )
336325 }
337326}
338327
339- impl < T > Into < ColorType < T > > for Vec < ARGBInts >
328+ impl < T > From < Vec < ARGBInts > > for ColorType < T >
340329{
341330 /// Converts `Vec<(u8, u8, u8, u8)>` into [VariableARGBInteger]
342- fn into ( self ) -> ColorType < T >
331+ fn from ( value : Vec < ARGBInts > ) -> Self
343332 {
344- ColorType :: VariableARGBInteger ( self )
333+ ColorType :: VariableARGBInteger ( value )
345334 }
346335}
347336
348- impl < T > Into < ColorType < T > > for ColorIndex
337+ impl < T > From < ColorIndex > for ColorType < T >
349338{
350339 /// Converts `u8` into [Index]
351- fn into ( self ) -> ColorType < T >
340+ fn from ( value : ColorIndex ) -> Self
352341 {
353- ColorType :: Index ( self )
342+ ColorType :: Index ( value )
354343 }
355344}
356345
357- impl < T > Into < ColorType < T > > for Vec < ColorIndex >
346+ impl < T > From < Vec < ColorIndex > > for ColorType < T >
358347{
359348 /// Converts `Vec<u8>` into [VariableIndex]
360- fn into ( self ) -> ColorType < T >
349+ fn from ( value : Vec < ColorIndex > ) -> Self
361350 {
362- ColorType :: VariableIndex ( self )
351+ ColorType :: VariableIndex ( value )
363352 }
364353}
365354
0 commit comments