From 2eae77b0dcf2c5e79304eec7c71142b109fe9dd8 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Sat, 19 Nov 2022 18:59:56 +0100 Subject: [PATCH] clippy fixes --- src/lib.rs | 18 +++++++++--------- tests/test.rs | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 692f943..f46a87b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,7 +119,7 @@ pub enum Alignment { /// The easiest way to create a Cell is just by using `string.into()`, which /// uses the **unicode width** of the string (see the `unicode_width` crate). /// However, the fields are public, if you wish to provide your own length. -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Eq, Debug, Clone)] pub struct Cell { /// The string to display when this cell gets rendered. pub contents: String, @@ -144,7 +144,7 @@ impl From for Cell { impl<'a> From<&'a str> for Cell { fn from(string: &'a str) -> Self { Self { - width: UnicodeWidthStr::width(&*string), + width: UnicodeWidthStr::width(string), contents: string.into(), alignment: Alignment::Left, } @@ -152,7 +152,7 @@ impl<'a> From<&'a str> for Cell { } /// Direction cells should be written in — either across, or downwards. -#[derive(PartialEq, Debug, Copy, Clone)] +#[derive(PartialEq, Eq, Debug, Copy, Clone)] pub enum Direction { /// Starts at the top left and moves rightwards, going back to the first /// column for a new row, like a typewriter. @@ -168,7 +168,7 @@ pub type Width = usize; /// The text to put in between each pair of columns. /// This does not include any spaces used when aligning cells. -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] pub enum Filling { /// A certain number of spaces should be used as the separator. Spaces(Width), @@ -189,7 +189,7 @@ impl Filling { /// The user-assignable options for a grid view that should be passed to /// [`Grid::new()`](struct.Grid.html#method.new). -#[derive(PartialEq, Debug)] +#[derive(Debug)] pub struct GridOptions { /// The direction that the cells should be written in — either /// across, or downwards. @@ -199,7 +199,7 @@ pub struct GridOptions { pub filling: Filling, } -#[derive(PartialEq, Debug)] +#[derive(PartialEq, Eq, Debug)] struct Dimensions { /// The number of lines in the grid. num_lines: Width, @@ -224,7 +224,7 @@ impl Dimensions { /// Everything needed to format the cells with the grid options. /// /// For more information, see the [`term_grid` crate documentation](index.html). -#[derive(PartialEq, Debug)] +#[derive(Debug)] pub struct Grid { options: GridOptions, cells: Vec, @@ -412,7 +412,7 @@ impl Grid { /// /// This type implements `Display`, so you can get the textual version /// of the grid by calling `.to_string()`. -#[derive(PartialEq, Debug)] +#[derive(Debug)] pub struct Display<'grid> { /// The grid to display. grid: &'grid Grid, @@ -520,7 +520,7 @@ impl fmt::Display for Display<'_> { /// Pad a string with the given number of spaces. fn spaces(length: usize) -> String { - repeat(" ").take(length).collect() + " ".repeat(length) } /// Pad a string with the given alignment and number of spaces. diff --git a/tests/test.rs b/tests/test.rs index 480e4c3..f9b0772 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -46,7 +46,7 @@ fn one_item_just_over() { grid.add(Cell::from("1234567890!")); - assert_eq!(grid.fit_into_width(10), None); + assert!(grid.fit_into_width(10).is_none()); } #[test] @@ -95,7 +95,7 @@ fn two_big_items() { "oudisnuthasuouneohbueobaugceoduhbsauglcobeuhnaeouosbubaoecgueoubeohubeo", )); - assert_eq!(grid.fit_into_width(40), None); + assert!(grid.fit_into_width(40).is_none()); } #[test] @@ -188,7 +188,7 @@ fn huge_separator() { grid.add("a".into()); grid.add("b".into()); - assert_eq!(grid.fit_into_width(99), None); + assert!(grid.fit_into_width(99).is_none()); } #[test]