Skip to content

Commit

Permalink
Fix various warnings and issues (#79)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
MichaelAquilina authored Jun 8, 2020
1 parent 07425ea commit 2b94a69
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl ColoredString {
/// assert_eq!(cstr.fgcolor(), None);
/// ```
pub fn fgcolor(&self) -> Option<Color> {
self.fgcolor.as_ref().map(|x| *x)
self.fgcolor.as_ref().copied()
}

/// Get the current background color applied.
Expand All @@ -321,7 +321,7 @@ impl ColoredString {
/// assert_eq!(cstr.bgcolor(), None);
/// ```
pub fn bgcolor(&self) -> Option<Color> {
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`].
Expand All @@ -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"))]
Expand Down
8 changes: 3 additions & 5 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -284,6 +281,7 @@ mod tests {
}
}

#[test]
fn test_style_contains() {
let mut style = Style(Styles::Bold.to_u8());
style.add(Styles::Italic);
Expand Down

0 comments on commit 2b94a69

Please sign in to comment.