From 3c4603dc7b08c9fa8630bbd39a062a8453debe05 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sat, 22 Mar 2025 20:32:51 -0700 Subject: [PATCH] Address Clippy warnings --- boot_diags/src/app.rs | 16 ++++++++-------- boot_diags/src/main.rs | 1 - core/src/components/footer.rs | 1 + core/src/components/left.rs | 4 ++-- core/src/components/right.rs | 4 ++-- core/src/components/title.rs | 1 + core/src/config.rs | 4 ++-- core/src/line.rs | 2 +- core/src/tasks.rs | 12 ++++++++---- deja_vu/src/app.rs | 19 +++++++++---------- deja_vu/src/main.rs | 1 - pe_menu/src/app.rs | 8 ++++---- pe_menu/src/main.rs | 1 - 13 files changed, 38 insertions(+), 36 deletions(-) diff --git a/boot_diags/src/app.rs b/boot_diags/src/app.rs index 998c62e..c6d7caf 100644 --- a/boot_diags/src/app.rs +++ b/boot_diags/src/app.rs @@ -17,11 +17,11 @@ use crate::diags; use core::{ action::Action, components::{ - footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, state::StatefulList, - title::Title, Component, + Component, footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, + state::StatefulList, title::Title, }, config::Config, - line::{get_disk_description_right, get_part_description, DVLine}, + line::{DVLine, get_disk_description_right, get_part_description}, state::{CloneSettings, Mode}, system::{ boot::{self, SafeMode}, @@ -894,7 +894,7 @@ fn build_right_items(app: &App) -> Action { line_colors: vec![Color::Reset], }, ]); - header_lines.append(&mut get_disk_description_right(&disk, Some(parts))); + header_lines.append(&mut get_disk_description_right(disk, Some(parts))); // Add header if !header_lines.is_empty() { @@ -957,10 +957,10 @@ fn build_right_items(app: &App) -> Action { let disk_list = app.clone.disk_list.lock().unwrap(); disk_list .iter() - .for_each(|disk| items.push(get_disk_description_right(&disk, None))); + .for_each(|disk| items.push(get_disk_description_right(disk, None))); } Mode::SelectParts => { - vec!["Boot", "OS"].iter().for_each(|s| { + ["Boot", "OS"].iter().for_each(|s| { labels.push(vec![DVLine { line_parts: vec![String::from(*s)], line_colors: vec![Color::Cyan], @@ -971,12 +971,12 @@ fn build_right_items(app: &App) -> Action { let disk_list = app.clone.disk_list.lock().unwrap(); if let Some(disk) = disk_list.get(index) { // Disk Details - items.push(get_disk_description_right(&disk, None)); + items.push(get_disk_description_right(disk, None)); // Partition Details disk.parts .iter() - .for_each(|part| items.push(get_part_description(&part))); + .for_each(|part| items.push(get_part_description(part))); } } } diff --git a/boot_diags/src/main.rs b/boot_diags/src/main.rs index 7128445..fe8b922 100644 --- a/boot_diags/src/main.rs +++ b/boot_diags/src/main.rs @@ -15,7 +15,6 @@ // use clap::Parser; use color_eyre::Result; -use core; use crate::app::App; diff --git a/core/src/components/footer.rs b/core/src/components/footer.rs index d266be2..2ab7406 100644 --- a/core/src/components/footer.rs +++ b/core/src/components/footer.rs @@ -51,6 +51,7 @@ impl Component for Footer { } fn update(&mut self, action: Action) -> Result> { + #[allow(clippy::single_match)] match action { Action::UpdateFooter(text) => self.text = text, _ => {} diff --git a/core/src/components/left.rs b/core/src/components/left.rs index eb27244..0f7112f 100644 --- a/core/src/components/left.rs +++ b/core/src/components/left.rs @@ -21,7 +21,7 @@ use ratatui::{ }; use tokio::sync::mpsc::UnboundedSender; -use super::{state::StatefulList, Component}; +use super::{Component, state::StatefulList}; use crate::{action::Action, config::Config}; #[derive(Default)] @@ -167,7 +167,7 @@ impl Component for Left { .map(|(index, item)| { let mut style = Style::default(); let text = if self.selections[0].is_some_and(|first_index| first_index == index) { - if let Some(label) = self.labels.get(0) { + if let Some(label) = self.labels.first() { style = style.yellow(); label.as_str() } else { diff --git a/core/src/components/right.rs b/core/src/components/right.rs index e7c18b6..04a8d16 100644 --- a/core/src/components/right.rs +++ b/core/src/components/right.rs @@ -21,7 +21,7 @@ use ratatui::{ }; use tokio::sync::mpsc::UnboundedSender; -use super::{state::StatefulList, Component}; +use super::{Component, state::StatefulList}; use crate::{action::Action, config::Config, line::DVLine}; #[derive(Default)] @@ -150,7 +150,7 @@ impl Component for Right { // First selection if let Some(first_index) = self.get_first() { if let Some(first_desc) = self.list.get(first_index) { - if let Some(label) = self.list_labels.get(0) { + if let Some(label) = self.list_labels.first() { label .iter() .for_each(|dv| body_text.push(dv.as_line().bold())); diff --git a/core/src/components/title.rs b/core/src/components/title.rs index f8e7dee..dd5a09a 100644 --- a/core/src/components/title.rs +++ b/core/src/components/title.rs @@ -51,6 +51,7 @@ impl Component for Title { } fn update(&mut self, action: Action) -> Result> { + #[allow(clippy::match_single_binding)] match action { _ => {} } diff --git a/core/src/config.rs b/core/src/config.rs index 2878c20..105b705 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -23,7 +23,7 @@ use derive_deref::{Deref, DerefMut}; use directories::ProjectDirs; use lazy_static::lazy_static; use ratatui::style::{Color, Modifier, Style}; -use serde::{de::Deserializer, Deserialize}; +use serde::{Deserialize, de::Deserializer}; use tracing::error; use crate::{action::Action, state::Mode}; @@ -54,7 +54,7 @@ pub struct Config { pub styles: Styles, } -pub static PROJECT_NAME: &'static str = "DEJA-VU"; +pub static PROJECT_NAME: &str = "DEJA-VU"; lazy_static! { //pub static ref PROJECT_NAME: String = env!("CARGO_PKG_NAME").to_uppercase().to_string(); pub static ref DATA_FOLDER: Option = diff --git a/core/src/line.rs b/core/src/line.rs index c618451..5a70312 100644 --- a/core/src/line.rs +++ b/core/src/line.rs @@ -77,7 +77,7 @@ pub fn get_disk_description_right( let mut line_parts = vec![line.clone()]; let mut line_colors = vec![Color::Reset]; if let Some(indicies) = &boot_os_indicies { - let boot_index = indicies.get(0); + let boot_index = indicies.first(); if boot_index.is_some_and(|i| i == &index) { line_parts.push(String::from(" <-- Boot Partition")); line_colors.push(Color::Cyan); diff --git a/core/src/tasks.rs b/core/src/tasks.rs index b0bd7a9..dde4d36 100644 --- a/core/src/tasks.rs +++ b/core/src/tasks.rs @@ -20,7 +20,7 @@ use std::{ path::PathBuf, process::{Command, Stdio}, sync::{Arc, Mutex}, - thread::{self, sleep, JoinHandle}, + thread::{self, JoinHandle, sleep}, time::Duration, }; @@ -180,7 +180,7 @@ impl Tasks { )); } TaskType::Diskpart(ref script) => { - self.cur_handle = Some(run_task_diskpart(&script, task_tx)); + self.cur_handle = Some(run_task_diskpart(script, task_tx)); } TaskType::ScanDisks => { let disk_list_arc = self.disk_list.clone(); @@ -261,7 +261,9 @@ fn run_task_command( let stdout = parse_bytes_as_str(output.stdout.to_owned()); let task_result = TaskResult::Output(stdout, stderr, output.status.success()); let err_str = format!("Failed to send TaskResult: {:?}", &task_result); - task_tx.send(task_result).expect(err_str.as_str()); + task_tx + .send(task_result) + .unwrap_or_else(|_| panic!("{}", err_str)); } } }) @@ -280,7 +282,9 @@ fn run_task_diskpart(script: &str, task_tx: mpsc::UnboundedSender) - let stdout = parse_bytes_as_str(output.stdout.to_owned()); let task_result = TaskResult::Output(stdout, stderr, output.status.success()); let err_str = format!("Failed to send TaskResult: {:?}", &task_result); - task_tx.send(task_result).expect(err_str.as_str()); + task_tx + .send(task_result) + .unwrap_or_else(|_| panic!("{}", err_str)); }) } else { // Simulate task if not running under Windows diff --git a/deja_vu/src/app.rs b/deja_vu/src/app.rs index 635b62a..91e2947 100644 --- a/deja_vu/src/app.rs +++ b/deja_vu/src/app.rs @@ -16,11 +16,11 @@ use core::{ action::Action, components::{ - footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, state::StatefulList, - title::Title, Component, + Component, footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, + state::StatefulList, title::Title, }, config::Config, - line::{get_disk_description_right, get_part_description, DVLine}, + line::{DVLine, get_disk_description_right, get_part_description}, state::{CloneSettings, Mode}, system::{ boot, cpu::get_cpu_name, disk::PartitionTableType, diskpart::build_dest_format_script, @@ -100,7 +100,7 @@ impl App { } pub fn prev_mode(&mut self) -> Option { - let new_mode = match self.cur_mode { + match self.cur_mode { Mode::Home => Some(Mode::Home), Mode::Failed => Some(Mode::Failed), Mode::Done => Some(Mode::Done), @@ -122,8 +122,7 @@ impl App { | Mode::InjectDrivers | Mode::PEMenu | Mode::SetBootMode => panic!("This shouldn't happen?"), - }; - new_mode + } } pub fn next_mode(&mut self) -> Option { @@ -770,10 +769,10 @@ fn build_right_items(app: &App, cur_mode: Mode) -> Action { let disk_list = app.clone.disk_list.lock().unwrap(); disk_list .iter() - .for_each(|disk| items.push(get_disk_description_right(&disk, None))); + .for_each(|disk| items.push(get_disk_description_right(disk, None))); } Mode::SelectParts => { - vec!["Boot", "OS"].iter().for_each(|s| { + ["Boot", "OS"].iter().for_each(|s| { labels.push(vec![DVLine { line_parts: vec![String::from(*s)], line_colors: vec![Color::Cyan], @@ -784,12 +783,12 @@ fn build_right_items(app: &App, cur_mode: Mode) -> Action { let disk_list = app.clone.disk_list.lock().unwrap(); if let Some(disk) = disk_list.get(index) { // Disk Details - items.push(get_disk_description_right(&disk, None)); + items.push(get_disk_description_right(disk, None)); // Partition Details disk.parts .iter() - .for_each(|part| items.push(get_part_description(&part))); + .for_each(|part| items.push(get_part_description(part))); } } } diff --git a/deja_vu/src/main.rs b/deja_vu/src/main.rs index 39999d2..514c60a 100644 --- a/deja_vu/src/main.rs +++ b/deja_vu/src/main.rs @@ -15,7 +15,6 @@ // use clap::Parser; use color_eyre::Result; -use core; use crate::app::App; diff --git a/pe_menu/src/app.rs b/pe_menu/src/app.rs index b817f2f..6f10996 100644 --- a/pe_menu/src/app.rs +++ b/pe_menu/src/app.rs @@ -16,8 +16,8 @@ use core::{ action::Action, components::{ - footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, state::StatefulList, - title::Title, Component, + Component, footer::Footer, fps::FpsCounter, left::Left, popup, right::Right, + state::StatefulList, title::Title, }, config::Config, line::DVLine, @@ -230,7 +230,7 @@ impl App { // Run selected tool if let Some(tool) = self.list.get_selected() { info!("Run tool: {:?}", &tool); - self.tasks.add(build_tool_command(&self, &tool)); + self.tasks.add(build_tool_command(self, &tool)); } } Action::Resize(w, h) => self.handle_resize(tui, w, h)?, @@ -453,7 +453,7 @@ pub fn load_tools() -> Vec { entries .iter() .map(|entry| { - let contents = fs::read_to_string(&entry).expect("Failed to read tool config file"); + let contents = fs::read_to_string(entry).expect("Failed to read tool config file"); let tool: Tool = toml::from_str(&contents).expect("Failed to parse tool config file"); tool }) diff --git a/pe_menu/src/main.rs b/pe_menu/src/main.rs index 82b0996..738665b 100644 --- a/pe_menu/src/main.rs +++ b/pe_menu/src/main.rs @@ -15,7 +15,6 @@ // use clap::Parser; use color_eyre::Result; -use core; use crate::app::App;