Apply some clippy suggestions

This commit is contained in:
Wesley Moore 2022-08-11 12:07:47 +10:00 committed by Jimmy
parent 55346b5b79
commit 9126f0ae0b
5 changed files with 19 additions and 13 deletions

View file

@ -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<Duration, String> {
"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)),
}
}

View file

@ -66,7 +66,7 @@ impl Timer {
}
}
fn execute(execute: &Vec<String>) -> 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);
}

View file

@ -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);

View file

@ -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);

View file

@ -30,7 +30,7 @@ fn run_app<B: Backend>(
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<dyn Error>> {
// 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,
};