From 9126f0ae0b3b9b4e2b98cb606230d30e09ac1e5a Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Thu, 11 Aug 2022 12:07:47 +1000 Subject: [PATCH] Apply some clippy suggestions --- src/app.rs | 16 ++++++++++------ src/app/modes/timer.rs | 4 ++-- src/bricks_text.rs | 2 +- src/bricks_text/chars.rs | 4 ++-- src/main.rs | 6 ++++-- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/app.rs b/src/app.rs index 182aa7c..478138e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -77,13 +77,17 @@ impl App { no_seconds: false, }); match mode { - Mode::Clock { no_date, no_seconds, millis } => { + Mode::Clock { + no_date, + no_seconds, + millis, + } => { self.clock = Some(Clock { size: self.size, style, - show_date: !no_date.to_owned(), - show_millis: millis.to_owned(), - show_secs: !*no_seconds, + show_date: !no_date, + show_millis: *millis, + show_secs: !no_seconds, }); } Mode::Timer { @@ -97,7 +101,7 @@ impl App { DurationFormat::HourMinSecDeci }; self.timer = Some(Timer::new( - duration.to_owned(), + *duration, self.size, style, format, @@ -162,7 +166,7 @@ fn parse_duration(s: &str) -> Result { "m" => Ok(Duration::minutes(num)), "h" => Ok(Duration::hours(num)), "d" => Ok(Duration::days(num)), - _ => Err(format!("Invalid duration: {}", s).into()), + _ => Err(format!("Invalid duration: {}", s)), } } diff --git a/src/app/modes/timer.rs b/src/app/modes/timer.rs index 4da167f..c0fa727 100644 --- a/src/app/modes/timer.rs +++ b/src/app/modes/timer.rs @@ -66,7 +66,7 @@ impl Timer { } } -fn execute(execute: &Vec) -> String { +fn execute(execute: &[String]) -> String { let mut cmd = Command::new("sh"); cmd.arg("-c"); let cmd_str = execute.join(" "); @@ -90,7 +90,7 @@ impl Widget for &Timer { fn render(self, area: Rect, buf: &mut Buffer) { let remaining_time = self.remaining_time(); let time_str = if remaining_time < Duration::zero() { - if self.execute.len() > 0 && self.execute_result.borrow().is_none() { + if !self.execute.is_empty() && self.execute_result.borrow().is_none() { let result = execute(&self.execute); *self.execute_result.borrow_mut() = Some(result); } diff --git a/src/bricks_text.rs b/src/bricks_text.rs index ebcf70a..9a89b53 100644 --- a/src/bricks_text.rs +++ b/src/bricks_text.rs @@ -30,7 +30,7 @@ impl BricksText { impl Widget for &BricksText { fn render(self, area: tui::layout::Rect, buf: &mut tui::buffer::Buffer) { - let mut area = area.clone(); + let mut area = area; for char in self.text.chars() { let Point(w, _) = BrickChar::size(self.size); let char = BrickChar::from(char); diff --git a/src/bricks_text/chars.rs b/src/bricks_text/chars.rs index 54e5084..714dae8 100644 --- a/src/bricks_text/chars.rs +++ b/src/bricks_text/chars.rs @@ -13,7 +13,7 @@ impl BrickChar { const UNIT_SIZE: Point = Point(3 * Self::H_UNIT, 5 * Self::V_UNIT); pub(crate) fn size(size: u16) -> Point { - Self::UNIT_SIZE.clone() * size + Self::UNIT_SIZE * size } pub(crate) fn from(char: char) -> BrickChar { @@ -219,7 +219,7 @@ impl BrickChar { for _ in 0..size { let mut p = from; for _ in (0..len).step_by(max(step.0, step.1).into()) { - if !p.in_area(&area) { + if !p.in_area(area) { break; } // println!("p = {:?} area = {:?}", p, area); diff --git a/src/main.rs b/src/main.rs index 13d40df..7129c76 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,7 @@ fn run_app( let timeout = tick_rate .checked_sub(last_tick.elapsed()) - .unwrap_or(Duration::from_secs(0)); + .unwrap_or(Duration::ZERO); if event::poll(timeout)? { if let Event::Key(key) = event::read()? { match key.code { @@ -61,7 +61,9 @@ fn main() -> Result<(), Box> { // create app and run it let low_rate = match app.mode { - Some(Mode::Clock { millis, no_seconds, .. }) => !millis || no_seconds, + Some(Mode::Clock { + millis, no_seconds, .. + }) => !millis || no_seconds, Some(Mode::Timer { no_millis, .. }) => no_millis, _ => false, };