@@ -163,6 +163,7 @@ pub struct Hsl {
163
163
}
164
164
165
165
impl Hsl {
166
+ /// Construct a new HSL color from it's components.
166
167
pub fn new (
167
168
hue : Option < f32 > ,
168
169
saturation : Option < f32 > ,
@@ -229,6 +230,7 @@ pub struct Hwb {
229
230
}
230
231
231
232
impl Hwb {
233
+ /// Construct a new HWB color from it's components.
232
234
pub fn new (
233
235
hue : Option < f32 > ,
234
236
whiteness : Option < f32 > ,
@@ -717,12 +719,14 @@ pub trait ColorParser<'i> {
717
719
Token :: Dimension {
718
720
value : v, ref unit, ..
719
721
} => {
720
- let degrees = match_ignore_ascii_case ! { & * unit,
722
+ let degrees = match_ignore_ascii_case ! { unit,
721
723
"deg" => v,
722
724
"grad" => v * 360. / 400. ,
723
725
"rad" => v * 360. / ( 2. * PI ) ,
724
726
"turn" => v * 360. ,
725
- _ => return Err ( location. new_unexpected_token_error( Token :: Ident ( unit. clone( ) ) ) ) ,
727
+ _ => {
728
+ return Err ( location. new_unexpected_token_error( Token :: Ident ( unit. clone( ) ) ) )
729
+ }
726
730
} ;
727
731
728
732
AngleOrNumber :: Angle { degrees }
@@ -775,7 +779,7 @@ impl Color {
775
779
/// Parse a <color> value, per CSS Color Module Level 3.
776
780
///
777
781
/// FIXME(#2) Deprecated CSS2 System Colors are not supported yet.
778
- pub fn parse < ' i , ' t > ( input : & mut Parser < ' i , ' t > ) -> Result < Color , ParseError < ' i , ( ) > > {
782
+ pub fn parse < ' i > ( input : & mut Parser < ' i , ' _ > ) -> Result < Color , ParseError < ' i , ( ) > > {
779
783
parse_color_with ( & DefaultColorParser , input)
780
784
}
781
785
}
@@ -844,7 +848,7 @@ pub trait FromParsedColor {
844
848
845
849
/// Parse a color hash, without the leading '#' character.
846
850
#[ inline]
847
- pub fn parse_hash_color < ' i , ' t , O > ( value : & [ u8 ] ) -> Result < O , ( ) >
851
+ pub fn parse_hash_color < ' i , O > ( value : & [ u8 ] ) -> Result < O , ( ) >
848
852
where
849
853
O : FromParsedColor ,
850
854
{
@@ -890,11 +894,11 @@ where
890
894
let token = input. next ( ) ?;
891
895
match * token {
892
896
Token :: Hash ( ref value) | Token :: IDHash ( ref value) => parse_hash_color ( value. as_bytes ( ) ) ,
893
- Token :: Ident ( ref value) => parse_color_keyword ( & * value) ,
897
+ Token :: Ident ( ref value) => parse_color_keyword ( value) ,
894
898
Token :: Function ( ref name) => {
895
899
let name = name. clone ( ) ;
896
900
return input. parse_nested_block ( |arguments| {
897
- parse_color_function ( color_parser, & * name, arguments)
901
+ parse_color_function ( color_parser, & name, arguments)
898
902
} ) ;
899
903
}
900
904
_ => Err ( ( ) ) ,
@@ -1433,7 +1437,7 @@ pub fn hwb_to_rgb(h: f32, w: f32, b: f32) -> (f32, f32, f32) {
1433
1437
/// except with h pre-multiplied by 3, to avoid some rounding errors.
1434
1438
#[ inline]
1435
1439
pub fn hsl_to_rgb ( hue : f32 , saturation : f32 , lightness : f32 ) -> ( f32 , f32 , f32 ) {
1436
- debug_assert ! ( hue >= 0.0 && hue <= 1.0 ) ;
1440
+ debug_assert ! ( ( 0.0 ..= 1.0 ) . contains ( & hue ) ) ;
1437
1441
1438
1442
fn hue_to_rgb ( m1 : f32 , m2 : f32 , mut h3 : f32 ) -> f32 {
1439
1443
if h3 < 0. {
@@ -1465,13 +1469,16 @@ pub fn hsl_to_rgb(hue: f32, saturation: f32, lightness: f32) -> (f32, f32, f32)
1465
1469
( red, green, blue)
1466
1470
}
1467
1471
1472
+ type IntoColorFn < Output > =
1473
+ fn ( l : Option < f32 > , a : Option < f32 > , b : Option < f32 > , alpha : Option < f32 > ) -> Output ;
1474
+
1468
1475
#[ inline]
1469
1476
fn parse_lab_like < ' i , ' t , P > (
1470
1477
color_parser : & P ,
1471
1478
arguments : & mut Parser < ' i , ' t > ,
1472
1479
lightness_range : f32 ,
1473
1480
a_b_range : f32 ,
1474
- into_color : fn ( l : Option < f32 > , a : Option < f32 > , b : Option < f32 > , alpha : Option < f32 > ) -> P :: Output ,
1481
+ into_color : IntoColorFn < P :: Output > ,
1475
1482
) -> Result < P :: Output , ParseError < ' i , P :: Error > >
1476
1483
where
1477
1484
P : ColorParser < ' i > ,
@@ -1497,7 +1504,7 @@ fn parse_lch_like<'i, 't, P>(
1497
1504
arguments : & mut Parser < ' i , ' t > ,
1498
1505
lightness_range : f32 ,
1499
1506
chroma_range : f32 ,
1500
- into_color : fn ( l : Option < f32 > , c : Option < f32 > , h : Option < f32 > , alpha : Option < f32 > ) -> P :: Output ,
1507
+ into_color : IntoColorFn < P :: Output > ,
1501
1508
) -> Result < P :: Output , ParseError < ' i , P :: Error > >
1502
1509
where
1503
1510
P : ColorParser < ' i > ,
@@ -1555,14 +1562,17 @@ where
1555
1562
) )
1556
1563
}
1557
1564
1565
+ type ComponentParseResult < ' i , R1 , R2 , R3 , Error > =
1566
+ Result < ( Option < R1 > , Option < R2 > , Option < R3 > , Option < f32 > ) , ParseError < ' i , Error > > ;
1567
+
1558
1568
/// Parse the color components and alpha with the modern [color-4] syntax.
1559
1569
pub fn parse_components < ' i , ' t , P , F1 , F2 , F3 , R1 , R2 , R3 > (
1560
1570
color_parser : & P ,
1561
1571
input : & mut Parser < ' i , ' t > ,
1562
1572
f1 : F1 ,
1563
1573
f2 : F2 ,
1564
1574
f3 : F3 ,
1565
- ) -> Result < ( Option < R1 > , Option < R2 > , Option < R3 > , Option < f32 > ) , ParseError < ' i , P :: Error > >
1575
+ ) -> ComponentParseResult < ' i , R1 , R2 , R3 , P :: Error >
1566
1576
where
1567
1577
P : ColorParser < ' i > ,
1568
1578
F1 : FnOnce ( & P , & mut Parser < ' i , ' t > ) -> Result < R1 , ParseError < ' i , P :: Error > > ,
0 commit comments