@@ -88,7 +88,7 @@ impl<'de> Deserialize<'de> for RGBA {
88
88
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
89
89
where D : Deserializer < ' de >
90
90
{
91
- let ( r, g, b, a) = try! ( Deserialize :: deserialize ( deserializer) ) ;
91
+ let ( r, g, b, a) = Deserialize :: deserialize ( deserializer) ? ;
92
92
Ok ( RGBA :: new ( r, g, b, a) )
93
93
}
94
94
}
@@ -141,7 +141,7 @@ impl Color {
141
141
///
142
142
/// FIXME(#2) Deprecated CSS2 System Colors are not supported yet.
143
143
pub fn parse < ' i , ' t > ( input : & mut Parser < ' i , ' t > ) -> Result < Color , BasicParseError < ' i > > {
144
- let token = try! ( input. next ( ) ) ;
144
+ let token = input. next ( ) ? ;
145
145
match token {
146
146
Token :: Hash ( ref value) | Token :: IDHash ( ref value) => {
147
147
Color :: parse_hash ( value. as_bytes ( ) )
@@ -162,26 +162,26 @@ impl Color {
162
162
pub fn parse_hash ( value : & [ u8 ] ) -> Result < Self , ( ) > {
163
163
match value. len ( ) {
164
164
8 => Ok ( rgba (
165
- try! ( from_hex ( value[ 0 ] ) ) * 16 + try! ( from_hex ( value[ 1 ] ) ) ,
166
- try! ( from_hex ( value[ 2 ] ) ) * 16 + try! ( from_hex ( value[ 3 ] ) ) ,
167
- try! ( from_hex ( value[ 4 ] ) ) * 16 + try! ( from_hex ( value[ 5 ] ) ) ,
168
- try! ( from_hex ( value[ 6 ] ) ) * 16 + try! ( from_hex ( value[ 7 ] ) ) ) ,
165
+ from_hex ( value[ 0 ] ) ? * 16 + from_hex ( value[ 1 ] ) ? ,
166
+ from_hex ( value[ 2 ] ) ? * 16 + from_hex ( value[ 3 ] ) ? ,
167
+ from_hex ( value[ 4 ] ) ? * 16 + from_hex ( value[ 5 ] ) ? ,
168
+ from_hex ( value[ 6 ] ) ? * 16 + from_hex ( value[ 7 ] ) ? ) ,
169
169
) ,
170
170
6 => Ok ( rgb (
171
- try! ( from_hex ( value[ 0 ] ) ) * 16 + try! ( from_hex ( value[ 1 ] ) ) ,
172
- try! ( from_hex ( value[ 2 ] ) ) * 16 + try! ( from_hex ( value[ 3 ] ) ) ,
173
- try! ( from_hex ( value[ 4 ] ) ) * 16 + try! ( from_hex ( value[ 5 ] ) ) ) ,
171
+ from_hex ( value[ 0 ] ) ? * 16 + from_hex ( value[ 1 ] ) ? ,
172
+ from_hex ( value[ 2 ] ) ? * 16 + from_hex ( value[ 3 ] ) ? ,
173
+ from_hex ( value[ 4 ] ) ? * 16 + from_hex ( value[ 5 ] ) ? ) ,
174
174
) ,
175
175
4 => Ok ( rgba (
176
- try! ( from_hex ( value[ 0 ] ) ) * 17 ,
177
- try! ( from_hex ( value[ 1 ] ) ) * 17 ,
178
- try! ( from_hex ( value[ 2 ] ) ) * 17 ,
179
- try! ( from_hex ( value[ 3 ] ) ) * 17 ) ,
176
+ from_hex ( value[ 0 ] ) ? * 17 ,
177
+ from_hex ( value[ 1 ] ) ? * 17 ,
178
+ from_hex ( value[ 2 ] ) ? * 17 ,
179
+ from_hex ( value[ 3 ] ) ? * 17 ) ,
180
180
) ,
181
181
3 => Ok ( rgb (
182
- try! ( from_hex ( value[ 0 ] ) ) * 17 ,
183
- try! ( from_hex ( value[ 1 ] ) ) * 17 ,
184
- try! ( from_hex ( value[ 2 ] ) ) * 17 ) ,
182
+ from_hex ( value[ 0 ] ) ? * 17 ,
183
+ from_hex ( value[ 1 ] ) ? * 17 ,
184
+ from_hex ( value[ 2 ] ) ? * 17 ) ,
185
185
) ,
186
186
_ => Err ( ( ) )
187
187
}
@@ -420,14 +420,14 @@ fn parse_color_function<'i, 't>(name: &str, arguments: &mut Parser<'i, 't>) -> R
420
420
421
421
let alpha = if !arguments. is_exhausted ( ) {
422
422
if uses_commas {
423
- try! ( arguments. expect_comma ( ) ) ;
423
+ arguments. expect_comma ( ) ? ;
424
424
} else {
425
- match try! ( arguments. next ( ) ) {
425
+ match arguments. next ( ) ? {
426
426
Token :: Delim ( '/' ) => { } ,
427
427
t => return Err ( BasicParseError :: UnexpectedToken ( t) ) ,
428
428
} ;
429
429
} ;
430
- let token = try! ( arguments. next ( ) ) ;
430
+ let token = arguments. next ( ) ? ;
431
431
match token {
432
432
Token :: Number { value : v, .. } => {
433
433
clamp_unit_f32 ( v)
@@ -443,7 +443,7 @@ fn parse_color_function<'i, 't>(name: &str, arguments: &mut Parser<'i, 't>) -> R
443
443
255
444
444
} ;
445
445
446
- try! ( arguments. expect_exhausted ( ) ) ;
446
+ arguments. expect_exhausted ( ) ? ;
447
447
Ok ( rgba ( red, green, blue, alpha) )
448
448
}
449
449
@@ -457,36 +457,36 @@ fn parse_rgb_components_rgb<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
457
457
458
458
// Either integers or percentages, but all the same type.
459
459
// https://drafts.csswg.org/css-color/#rgb-functions
460
- match try! ( arguments. next ( ) ) {
460
+ match arguments. next ( ) ? {
461
461
Token :: Number { value : v, .. } => {
462
462
red = clamp_floor_256_f32 ( v) ;
463
- green = clamp_floor_256_f32 ( match try! ( arguments. next ( ) ) {
463
+ green = clamp_floor_256_f32 ( match arguments. next ( ) ? {
464
464
Token :: Number { value : v, .. } => v,
465
465
Token :: Comma => {
466
466
uses_commas = true ;
467
- try! ( arguments. expect_number ( ) )
467
+ arguments. expect_number ( ) ?
468
468
}
469
469
t => return Err ( BasicParseError :: UnexpectedToken ( t) )
470
470
} ) ;
471
471
if uses_commas {
472
- try! ( arguments. expect_comma ( ) ) ;
472
+ arguments. expect_comma ( ) ? ;
473
473
}
474
- blue = clamp_floor_256_f32 ( try! ( arguments. expect_number ( ) ) ) ;
474
+ blue = clamp_floor_256_f32 ( arguments. expect_number ( ) ? ) ;
475
475
}
476
476
Token :: Percentage { unit_value, .. } => {
477
477
red = clamp_unit_f32 ( unit_value) ;
478
- green = clamp_unit_f32 ( match try! ( arguments. next ( ) ) {
478
+ green = clamp_unit_f32 ( match arguments. next ( ) ? {
479
479
Token :: Percentage { unit_value, .. } => unit_value,
480
480
Token :: Comma => {
481
481
uses_commas = true ;
482
- try! ( arguments. expect_percentage ( ) )
482
+ arguments. expect_percentage ( ) ?
483
483
}
484
484
t => return Err ( BasicParseError :: UnexpectedToken ( t) )
485
485
} ) ;
486
486
if uses_commas {
487
- try! ( arguments. expect_comma ( ) ) ;
487
+ arguments. expect_comma ( ) ? ;
488
488
}
489
- blue = clamp_unit_f32 ( try! ( arguments. expect_percentage ( ) ) ) ;
489
+ blue = clamp_unit_f32 ( arguments. expect_percentage ( ) ? ) ;
490
490
}
491
491
t => return Err ( BasicParseError :: UnexpectedToken ( t) )
492
492
} ;
@@ -498,7 +498,7 @@ fn parse_rgb_components_hsl<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
498
498
let mut uses_commas = false ;
499
499
// Hue given as an angle
500
500
// https://drafts.csswg.org/css-values/#angles
501
- let token = try! ( arguments. next ( ) ) ;
501
+ let token = arguments. next ( ) ? ;
502
502
let hue_degrees = match token {
503
503
Token :: Number { value : v, .. } => Ok ( v) ,
504
504
Token :: Dimension { value : v, ref unit, .. } => {
@@ -512,28 +512,28 @@ fn parse_rgb_components_hsl<'i, 't>(arguments: &mut Parser<'i, 't>) -> Result<(u
512
512
}
513
513
t => return Err ( BasicParseError :: UnexpectedToken ( t) )
514
514
} ;
515
- let hue_degrees = try! ( hue_degrees. map_err ( |( ) | BasicParseError :: UnexpectedToken ( token) ) ) ;
515
+ let hue_degrees = hue_degrees. map_err ( |( ) | BasicParseError :: UnexpectedToken ( token) ) ? ;
516
516
// Subtract an integer before rounding, to avoid some rounding errors:
517
517
let hue_normalized_degrees = hue_degrees - 360. * ( hue_degrees / 360. ) . floor ( ) ;
518
518
let hue = hue_normalized_degrees / 360. ;
519
519
520
520
// Saturation and lightness are clamped to 0% ... 100%
521
521
// https://drafts.csswg.org/css-color/#the-hsl-notation
522
- let saturation = match try! ( arguments. next ( ) ) {
522
+ let saturation = match arguments. next ( ) ? {
523
523
Token :: Percentage { unit_value, .. } => unit_value,
524
524
Token :: Comma => {
525
525
uses_commas = true ;
526
- try! ( arguments. expect_percentage ( ) )
526
+ arguments. expect_percentage ( ) ?
527
527
}
528
528
t => return Err ( BasicParseError :: UnexpectedToken ( t) )
529
529
} ;
530
530
let saturation = saturation. max ( 0. ) . min ( 1. ) ;
531
531
532
532
if uses_commas {
533
- try! ( arguments. expect_comma ( ) ) ;
533
+ arguments. expect_comma ( ) ? ;
534
534
}
535
535
536
- let lightness = try! ( arguments. expect_percentage ( ) ) ;
536
+ let lightness = arguments. expect_percentage ( ) ? ;
537
537
let lightness = lightness. max ( 0. ) . min ( 1. ) ;
538
538
539
539
// https://drafts.csswg.org/css-color/#hsl-color
0 commit comments