From c16d6fed4edd6dcff076c6dc3a691740b4b10004 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Fri, 14 Feb 2020 18:28:09 -0500 Subject: [PATCH] clippy --- src/builtin/color/other.rs | 8 ++++---- src/builtin/color/rgb.rs | 8 ++++---- src/color/mod.rs | 4 ++-- src/css.rs | 4 ++-- src/lib.rs | 23 +++++++++++++++-------- src/value/number.rs | 1 + 6 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/builtin/color/other.rs b/src/builtin/color/other.rs index 1ec8d98..dcacdb3 100644 --- a/src/builtin/color/other.rs +++ b/src/builtin/color/other.rs @@ -38,7 +38,7 @@ pub(crate) fn register(f: &mut BTreeMap) { _ => todo!("expected either unitless or % number for $blue") }; - if !red.is_none() || !green.is_none() || !blue.is_none() { + if red.is_some() || green.is_some() || blue.is_some() { return Some(Value::Color(Color::from_rgba(red.unwrap_or(color.red()), green.unwrap_or(color.green()), blue.unwrap_or(color.blue()), alpha.unwrap_or(color.alpha())))) } @@ -62,14 +62,14 @@ pub(crate) fn register(f: &mut BTreeMap) { _ => todo!("expected either unitless or % number for luminance"), }; - if !hue.is_none() || !saturation.is_none() || !luminance.is_none() { + if hue.is_some() || saturation.is_some() || luminance.is_some() { // Color::as_hsla() returns more exact values than Color::hue(), etc. let (this_hue, this_saturation, this_luminance, this_alpha) = color.as_hsla(); return Some(Value::Color(Color::from_hsla(hue.unwrap_or(this_hue), saturation.unwrap_or(this_saturation), luminance.unwrap_or(this_luminance), alpha.unwrap_or(this_alpha)))) } - Some(Value::Color(if !alpha.is_none() { - color.with_alpha(alpha.unwrap()) + Some(Value::Color(if let Some(a) = alpha { + color.with_alpha(a) } else { color })) diff --git a/src/builtin/color/rgb.rs b/src/builtin/color/rgb.rs index 23b11bd..e7d103c 100644 --- a/src/builtin/color/rgb.rs +++ b/src/builtin/color/rgb.rs @@ -42,7 +42,7 @@ pub(crate) fn register(f: &mut BTreeMap) { _ => todo!("missing element $green") }; - assert_eq!(channels.len(), 3usize); + assert_eq!(channels.len(), 3_usize); let blue = match channels.pop() { Some(Value::Dimension(n, Unit::None)) => n, @@ -103,19 +103,19 @@ pub(crate) fn register(f: &mut BTreeMap) { }); decl!(f "red", |args, _| { match arg!(args, 0, "color") { - Value::Color(c) => Some(Value::Dimension(Number::from(c.red()), Unit::None)), + Value::Color(c) => Some(Value::Dimension(c.red(), Unit::None)), _ => todo!("non-color given to builtin function `red()`") } }); decl!(f "green", |args, _| { match arg!(args, 0, "color") { - Value::Color(c) => Some(Value::Dimension(Number::from(c.green()), Unit::None)), + Value::Color(c) => Some(Value::Dimension(c.green(), Unit::None)), _ => todo!("non-color given to builtin function `green()`") } }); decl!(f "blue", |args, _| { match arg!(args, 0, "color") { - Value::Color(c) => Some(Value::Dimension(Number::from(c.blue()), Unit::None)), + Value::Color(c) => Some(Value::Dimension(c.blue(), Unit::None)), _ => todo!("non-color given to builtin function `blue()`") } }); diff --git a/src/color/mod.rs b/src/color/mod.rs index 7566424..753bb64 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -111,7 +111,7 @@ impl Color { Color::from_rgba( self.red * weight1.clone() + other.red * weight2.clone(), self.green * weight1.clone() + other.green * weight2.clone(), - self.blue * weight1.clone() + other.blue * weight2, + self.blue * weight1 + other.blue * weight2, self.alpha * weight.clone() + other.alpha * (Number::from(1) - weight), ) } @@ -188,7 +188,7 @@ impl Color { let lightness = (min.clone() + max.clone()) / Number::from(2); - let saturation = if &min == &max { + let saturation = if min == max { Number::from(0) } else { let d = max.clone() - min.clone(); diff --git a/src/css.rs b/src/css.rs index c17f036..54599b7 100644 --- a/src/css.rs +++ b/src/css.rs @@ -14,7 +14,7 @@ enum Toplevel { #[derive(Debug, Clone)] enum BlockEntry { - Style(Style), + Style(Box