From 2b94a69b7d2f9036ba72fa89fca7d5d482ba2b83 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 8 Jun 2020 12:02:32 +0100 Subject: [PATCH] Fix various warnings and issues (#79) * Use copied instead of map(|x| x) * Remove redundant parenthesis * More efficient to pass enum by value * Add missing #[test] annotation * Remove unused imports * Enable cache on travis * Add clippy to travis --- .travis.yml | 9 +++++++++ src/lib.rs | 6 +++--- src/style.rs | 8 +++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3ff2067..9062dfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,15 @@ rust: - beta - stable +cache: cargo + +before_script: + - rustup component add clippy + +script: + - cargo test --verbose + - cargo clippy -- -Dwarnings + matrix: allow_failures: - rust: nightly diff --git a/src/lib.rs b/src/lib.rs index 891737d..444b9fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -308,7 +308,7 @@ impl ColoredString { /// assert_eq!(cstr.fgcolor(), None); /// ``` pub fn fgcolor(&self) -> Option { - self.fgcolor.as_ref().map(|x| *x) + self.fgcolor.as_ref().copied() } /// Get the current background color applied. @@ -321,7 +321,7 @@ impl ColoredString { /// assert_eq!(cstr.bgcolor(), None); /// ``` pub fn bgcolor(&self) -> Option { - self.bgcolor.as_ref().map(|x| *x) + self.bgcolor.as_ref().copied() } /// Get the current [`Style`] which can be check if it contains a [`Styles`]. @@ -347,7 +347,7 @@ impl ColoredString { /// assert_eq!(cstr.is_plain(), true); /// ``` pub fn is_plain(&self) -> bool { - (self.bgcolor.is_none() && self.fgcolor.is_none() && self.style == style::CLEAR) + self.bgcolor.is_none() && self.fgcolor.is_none() && self.style == style::CLEAR } #[cfg(not(feature = "no-color"))] diff --git a/src/style.rs b/src/style.rs index 8836892..bf97acc 100644 --- a/src/style.rs +++ b/src/style.rs @@ -96,7 +96,7 @@ impl Style { /// assert_eq!(colored.style().contains(Styles::Italic), true); /// assert_eq!(colored.style().contains(Styles::Dimmed), false); /// ``` - pub fn contains(&self, style: Styles) -> bool { + pub fn contains(self, style: Styles) -> bool { let s = style.to_u8(); self.0 & s == s } @@ -120,8 +120,8 @@ mod tests { use super::*; mod u8_to_styles_invalid_is_none { + use super::super::Styles; use super::super::CLEARV; - use super::super::{Style, Styles}; #[test] fn empty_is_none() { @@ -174,9 +174,6 @@ mod tests { mod styles_combine_complex { use super::super::Styles::*; use super::super::{Style, Styles}; - use super::super::{ - BLINK, BOLD, DIMMED, HIDDEN, ITALIC, REVERSED, STRIKETHROUGH, UNDERLINE, - }; fn style_from_multiples(styles: &[Styles]) -> Style { let mut res = Style(styles[0].to_u8()); @@ -284,6 +281,7 @@ mod tests { } } + #[test] fn test_style_contains() { let mut style = Style(Styles::Bold.to_u8()); style.add(Styles::Italic);