Skip to content

Commit a44c83a

Browse files
committed
Address some clippy suggestions
1 parent 8d4c776 commit a44c83a

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/color.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub struct Hsl {
163163
}
164164

165165
impl Hsl {
166+
/// Construct a new HSL color from it's components.
166167
pub fn new(
167168
hue: Option<f32>,
168169
saturation: Option<f32>,
@@ -229,6 +230,7 @@ pub struct Hwb {
229230
}
230231

231232
impl Hwb {
233+
/// Construct a new HWB color from it's components.
232234
pub fn new(
233235
hue: Option<f32>,
234236
whiteness: Option<f32>,
@@ -717,12 +719,14 @@ pub trait ColorParser<'i> {
717719
Token::Dimension {
718720
value: v, ref unit, ..
719721
} => {
720-
let degrees = match_ignore_ascii_case! { &*unit,
722+
let degrees = match_ignore_ascii_case! { unit,
721723
"deg" => v,
722724
"grad" => v * 360. / 400.,
723725
"rad" => v * 360. / (2. * PI),
724726
"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+
}
726730
};
727731

728732
AngleOrNumber::Angle { degrees }
@@ -775,7 +779,7 @@ impl Color {
775779
/// Parse a <color> value, per CSS Color Module Level 3.
776780
///
777781
/// 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, ()>> {
779783
parse_color_with(&DefaultColorParser, input)
780784
}
781785
}
@@ -844,7 +848,7 @@ pub trait FromParsedColor {
844848

845849
/// Parse a color hash, without the leading '#' character.
846850
#[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, ()>
848852
where
849853
O: FromParsedColor,
850854
{
@@ -890,11 +894,11 @@ where
890894
let token = input.next()?;
891895
match *token {
892896
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),
894898
Token::Function(ref name) => {
895899
let name = name.clone();
896900
return input.parse_nested_block(|arguments| {
897-
parse_color_function(color_parser, &*name, arguments)
901+
parse_color_function(color_parser, &name, arguments)
898902
});
899903
}
900904
_ => Err(()),
@@ -1433,7 +1437,7 @@ pub fn hwb_to_rgb(h: f32, w: f32, b: f32) -> (f32, f32, f32) {
14331437
/// except with h pre-multiplied by 3, to avoid some rounding errors.
14341438
#[inline]
14351439
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));
14371441

14381442
fn hue_to_rgb(m1: f32, m2: f32, mut h3: f32) -> f32 {
14391443
if h3 < 0. {
@@ -1465,13 +1469,16 @@ pub fn hsl_to_rgb(hue: f32, saturation: f32, lightness: f32) -> (f32, f32, f32)
14651469
(red, green, blue)
14661470
}
14671471

1472+
type IntoColorFn<Output> =
1473+
fn(l: Option<f32>, a: Option<f32>, b: Option<f32>, alpha: Option<f32>) -> Output;
1474+
14681475
#[inline]
14691476
fn parse_lab_like<'i, 't, P>(
14701477
color_parser: &P,
14711478
arguments: &mut Parser<'i, 't>,
14721479
lightness_range: f32,
14731480
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>,
14751482
) -> Result<P::Output, ParseError<'i, P::Error>>
14761483
where
14771484
P: ColorParser<'i>,
@@ -1497,7 +1504,7 @@ fn parse_lch_like<'i, 't, P>(
14971504
arguments: &mut Parser<'i, 't>,
14981505
lightness_range: f32,
14991506
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>,
15011508
) -> Result<P::Output, ParseError<'i, P::Error>>
15021509
where
15031510
P: ColorParser<'i>,
@@ -1555,14 +1562,17 @@ where
15551562
))
15561563
}
15571564

1565+
type ComponentParseResult<'i, R1, R2, R3, Error> =
1566+
Result<(Option<R1>, Option<R2>, Option<R3>, Option<f32>), ParseError<'i, Error>>;
1567+
15581568
/// Parse the color components and alpha with the modern [color-4] syntax.
15591569
pub fn parse_components<'i, 't, P, F1, F2, F3, R1, R2, R3>(
15601570
color_parser: &P,
15611571
input: &mut Parser<'i, 't>,
15621572
f1: F1,
15631573
f2: F2,
15641574
f3: F3,
1565-
) -> Result<(Option<R1>, Option<R2>, Option<R3>, Option<f32>), ParseError<'i, P::Error>>
1575+
) -> ComponentParseResult<'i, R1, R2, R3, P::Error>
15661576
where
15671577
P: ColorParser<'i>,
15681578
F1: FnOnce(&P, &mut Parser<'i, 't>) -> Result<R1, ParseError<'i, P::Error>>,

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
6969

7070
pub use crate::color::{
7171
hsl_to_rgb, hwb_to_rgb, parse_color_keyword, parse_color_with, parse_hash_color, AngleOrNumber,
72-
Color, ColorFunction, ColorParser, FromParsedColor, Lab, Lch, NumberOrPercentage, Oklab, Oklch,
73-
PredefinedColorSpace, RGBA,
72+
Color, ColorFunction, ColorParser, FromParsedColor, Hsl, Hwb, Lab, Lch, NumberOrPercentage,
73+
Oklab, Oklch, PredefinedColorSpace, RGBA,
7474
};
7575
pub use crate::cow_rc_str::CowRcStr;
7676
pub use crate::from_bytes::{stylesheet_encoding, EncodingSupport};

0 commit comments

Comments
 (0)