@@ -42,14 +42,13 @@ where
4242
4343/// Parse a CSS color using the specified [`ColorParser`] and return a new color
4444/// value on success.
45- pub fn parse_color_with < ' i , ' t , P > (
45+ pub fn parse_color_with < ' i , P > (
4646 color_parser : & P ,
47- input : & mut Parser < ' i , ' t > ,
48- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
47+ input : & mut Parser < ' i , ' _ > ,
48+ ) -> Result < P :: Output , ParseError < P :: Error > >
4949where
5050 P : ColorParser < ' i > ,
5151{
52- let location = input. current_source_location ( ) ;
5352 let token = input. next ( ) ?;
5453 match * token {
5554 Token :: Hash ( ref value) | Token :: IDHash ( ref value) => {
@@ -64,16 +63,16 @@ where
6463 }
6564 _ => Err ( ( ) ) ,
6665 }
67- . map_err ( |( ) | location . new_unexpected_token_error ( token . clone ( ) ) )
66+ . map_err ( |( ) | ParseError :: unexpected_token ( ) )
6867}
6968
7069/// Parse one of the color functions: rgba(), lab(), color(), etc.
7170#[ inline]
72- fn parse_color_function < ' i , ' t , P > (
71+ fn parse_color_function < ' i , P > (
7372 color_parser : & P ,
7473 name : CowRcStr < ' i > ,
75- arguments : & mut Parser < ' i , ' t > ,
76- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
74+ arguments : & mut Parser ,
75+ ) -> Result < P :: Output , ParseError < P :: Error > >
7776where
7877 P : ColorParser < ' i > ,
7978{
@@ -102,7 +101,7 @@ where
102101
103102 "color" => parse_color_with_color_space( color_parser, arguments) ,
104103
105- _ => return Err ( arguments . new_unexpected_token_error ( Token :: Ident ( name ) ) ) ,
104+ _ => return Err ( ParseError :: unexpected_token ( ) ) ,
106105 } ?;
107106
108107 arguments. expect_exhausted ( ) ?;
@@ -115,8 +114,8 @@ where
115114#[ inline]
116115fn parse_alpha_component < ' i , ' t , P > (
117116 color_parser : & P ,
118- arguments : & mut Parser < ' i , ' t > ,
119- ) -> Result < f32 , ParseError < ' i , P :: Error > >
117+ arguments : & mut Parser ,
118+ ) -> Result < f32 , ParseError < P :: Error > >
120119where
121120 P : ColorParser < ' i > ,
122121{
@@ -128,8 +127,8 @@ where
128127
129128fn parse_legacy_alpha < ' i , ' t , P > (
130129 color_parser : & P ,
131- arguments : & mut Parser < ' i , ' t > ,
132- ) -> Result < f32 , ParseError < ' i , P :: Error > >
130+ arguments : & mut Parser ,
131+ ) -> Result < f32 , ParseError < P :: Error > >
133132where
134133 P : ColorParser < ' i > ,
135134{
@@ -143,8 +142,8 @@ where
143142
144143fn parse_modern_alpha < ' i , ' t , P > (
145144 color_parser : & P ,
146- arguments : & mut Parser < ' i , ' t > ,
147- ) -> Result < Option < f32 > , ParseError < ' i , P :: Error > >
145+ arguments : & mut Parser ,
146+ ) -> Result < Option < f32 > , ParseError < P :: Error > >
148147where
149148 P : ColorParser < ' i > ,
150149{
@@ -159,8 +158,8 @@ where
159158#[ inline]
160159fn parse_rgb < ' i , ' t , P > (
161160 color_parser : & P ,
162- arguments : & mut Parser < ' i , ' t > ,
163- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
161+ arguments : & mut Parser ,
162+ ) -> Result < P :: Output , ParseError < P :: Error > >
164163where
165164 P : ColorParser < ' i > ,
166165{
@@ -225,8 +224,8 @@ where
225224#[ inline]
226225fn parse_hsl < ' i , ' t , P > (
227226 color_parser : & P ,
228- arguments : & mut Parser < ' i , ' t > ,
229- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
227+ arguments : & mut Parser ,
228+ ) -> Result < P :: Output , ParseError < P :: Error > >
230229where
231230 P : ColorParser < ' i > ,
232231{
@@ -264,8 +263,8 @@ where
264263#[ inline]
265264fn parse_hwb < ' i , ' t , P > (
266265 color_parser : & P ,
267- arguments : & mut Parser < ' i , ' t > ,
268- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
266+ arguments : & mut Parser ,
267+ ) -> Result < P :: Output , ParseError < P :: Error > >
269268where
270269 P : ColorParser < ' i > ,
271270{
@@ -343,11 +342,11 @@ type IntoColorFn<Output> =
343342#[ inline]
344343fn parse_lab_like < ' i , ' t , P > (
345344 color_parser : & P ,
346- arguments : & mut Parser < ' i , ' t > ,
345+ arguments : & mut Parser ,
347346 lightness_range : f32 ,
348347 a_b_range : f32 ,
349348 into_color : IntoColorFn < P :: Output > ,
350- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
349+ ) -> Result < P :: Output , ParseError < P :: Error > >
351350where
352351 P : ColorParser < ' i > ,
353352{
@@ -369,11 +368,11 @@ where
369368#[ inline]
370369fn parse_lch_like < ' i , ' t , P > (
371370 color_parser : & P ,
372- arguments : & mut Parser < ' i , ' t > ,
371+ arguments : & mut Parser ,
373372 lightness_range : f32 ,
374373 chroma_range : f32 ,
375374 into_color : IntoColorFn < P :: Output > ,
376- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
375+ ) -> Result < P :: Output , ParseError < P :: Error > >
377376where
378377 P : ColorParser < ' i > ,
379378{
@@ -396,8 +395,8 @@ where
396395#[ inline]
397396fn parse_color_with_color_space < ' i , ' t , P > (
398397 color_parser : & P ,
399- arguments : & mut Parser < ' i , ' t > ,
400- ) -> Result < P :: Output , ParseError < ' i , P :: Error > >
398+ arguments : & mut Parser ,
399+ ) -> Result < P :: Output , ParseError < P :: Error > >
401400where
402401 P : ColorParser < ' i > ,
403402{
@@ -424,22 +423,22 @@ where
424423 ) )
425424}
426425
427- type ComponentParseResult < ' i , R1 , R2 , R3 , Error > =
428- Result < ( Option < R1 > , Option < R2 > , Option < R3 > , Option < f32 > ) , ParseError < ' i , Error > > ;
426+ type ComponentParseResult < R1 , R2 , R3 , Error > =
427+ Result < ( Option < R1 > , Option < R2 > , Option < R3 > , Option < f32 > ) , ParseError < Error > > ;
429428
430429/// Parse the color components and alpha with the modern [color-4] syntax.
431430pub fn parse_components < ' i , ' t , P , F1 , F2 , F3 , R1 , R2 , R3 > (
432431 color_parser : & P ,
433- input : & mut Parser < ' i , ' t > ,
432+ input : & mut Parser ,
434433 f1 : F1 ,
435434 f2 : F2 ,
436435 f3 : F3 ,
437- ) -> ComponentParseResult < ' i , R1 , R2 , R3 , P :: Error >
436+ ) -> ComponentParseResult < R1 , R2 , R3 , P :: Error >
438437where
439438 P : ColorParser < ' i > ,
440- F1 : FnOnce ( & P , & mut Parser < ' i , ' t > ) -> Result < R1 , ParseError < ' i , P :: Error > > ,
441- F2 : FnOnce ( & P , & mut Parser < ' i , ' t > ) -> Result < R2 , ParseError < ' i , P :: Error > > ,
442- F3 : FnOnce ( & P , & mut Parser < ' i , ' t > ) -> Result < R3 , ParseError < ' i , P :: Error > > ,
439+ F1 : FnOnce ( & P , & mut Parser ) -> Result < R1 , ParseError < P :: Error > > ,
440+ F2 : FnOnce ( & P , & mut Parser ) -> Result < R2 , ParseError < P :: Error > > ,
441+ F3 : FnOnce ( & P , & mut Parser ) -> Result < R3 , ParseError < P :: Error > > ,
443442{
444443 let r1 = parse_none_or ( input, |p| f1 ( color_parser, p) ) ?;
445444 let r2 = parse_none_or ( input, |p| f2 ( color_parser, p) ) ?;
@@ -450,9 +449,9 @@ where
450449 Ok ( ( r1, r2, r3, alpha) )
451450}
452451
453- fn parse_none_or < ' i , ' t , F , T , E > ( input : & mut Parser < ' i , ' t > , thing : F ) -> Result < Option < T > , E >
452+ fn parse_none_or < ' i , ' t , F , T , E > ( input : & mut Parser , thing : F ) -> Result < Option < T > , E >
454453where
455- F : FnOnce ( & mut Parser < ' i , ' t > ) -> Result < T , E > ,
454+ F : FnOnce ( & mut Parser ) -> Result < T , E > ,
456455{
457456 match input. try_parse ( |p| p. expect_ident_matching ( "none" ) ) {
458457 Ok ( _) => Ok ( None ) ,
@@ -980,11 +979,10 @@ pub trait ColorParser<'i> {
980979 /// Parse an `<angle>` or `<number>`.
981980 ///
982981 /// Returns the result in degrees.
983- fn parse_angle_or_number < ' t > (
982+ fn parse_angle_or_number (
984983 & self ,
985- input : & mut Parser < ' i , ' t > ,
986- ) -> Result < AngleOrNumber , ParseError < ' i , Self :: Error > > {
987- let location = input. current_source_location ( ) ;
984+ input : & mut Parser ,
985+ ) -> Result < AngleOrNumber , ParseError < Self :: Error > > {
988986 Ok ( match * input. next ( ) ? {
989987 Token :: Number { value, .. } => AngleOrNumber :: Number { value } ,
990988 Token :: Dimension {
@@ -995,45 +993,36 @@ pub trait ColorParser<'i> {
995993 "grad" => v * 360. / 400. ,
996994 "rad" => v * 360. / ( 2. * PI ) ,
997995 "turn" => v * 360. ,
998- _ => {
999- return Err ( location. new_unexpected_token_error( Token :: Ident ( unit. clone( ) ) ) )
1000- }
996+ _ => return Err ( ParseError :: unexpected_token( ) ) ,
1001997 } ;
1002998
1003999 AngleOrNumber :: Angle { degrees }
10041000 }
1005- ref t => return Err ( location . new_unexpected_token_error ( t . clone ( ) ) ) ,
1001+ _ => return Err ( ParseError :: unexpected_token ( ) ) ,
10061002 } )
10071003 }
10081004
10091005 /// Parse a `<percentage>` value.
10101006 ///
10111007 /// Returns the result in a number from 0.0 to 1.0.
1012- fn parse_percentage < ' t > (
1013- & self ,
1014- input : & mut Parser < ' i , ' t > ,
1015- ) -> Result < f32 , ParseError < ' i , Self :: Error > > {
1008+ fn parse_percentage ( & self , input : & mut Parser ) -> Result < f32 , ParseError < Self :: Error > > {
10161009 input. expect_percentage ( ) . map_err ( From :: from)
10171010 }
10181011
10191012 /// Parse a `<number>` value.
1020- fn parse_number < ' t > (
1021- & self ,
1022- input : & mut Parser < ' i , ' t > ,
1023- ) -> Result < f32 , ParseError < ' i , Self :: Error > > {
1013+ fn parse_number ( & self , input : & mut Parser ) -> Result < f32 , ParseError < Self :: Error > > {
10241014 input. expect_number ( ) . map_err ( From :: from)
10251015 }
10261016
10271017 /// Parse a `<number>` value or a `<percentage>` value.
1028- fn parse_number_or_percentage < ' t > (
1018+ fn parse_number_or_percentage (
10291019 & self ,
1030- input : & mut Parser < ' i , ' t > ,
1031- ) -> Result < NumberOrPercentage , ParseError < ' i , Self :: Error > > {
1032- let location = input. current_source_location ( ) ;
1020+ input : & mut Parser ,
1021+ ) -> Result < NumberOrPercentage , ParseError < Self :: Error > > {
10331022 Ok ( match * input. next ( ) ? {
10341023 Token :: Number { value, .. } => NumberOrPercentage :: Number { value } ,
10351024 Token :: Percentage { unit_value, .. } => NumberOrPercentage :: Percentage { unit_value } ,
1036- ref t => return Err ( location . new_unexpected_token_error ( t . clone ( ) ) ) ,
1025+ _ => return Err ( ParseError :: unexpected_token ( ) ) ,
10371026 } )
10381027 }
10391028}
@@ -1050,7 +1039,7 @@ impl Color {
10501039 /// Parse a <color> value, per CSS Color Module Level 3.
10511040 ///
10521041 /// FIXME(#2) Deprecated CSS2 System Colors are not supported yet.
1053- pub fn parse < ' i > ( input : & mut Parser < ' i , ' _ > ) -> Result < Color , ParseError < ' i , ( ) > > {
1042+ pub fn parse ( input : & mut Parser ) -> Result < Color , ParseError < ( ) > > {
10541043 parse_color_with ( & DefaultColorParser , input)
10551044 }
10561045}
0 commit comments