From 2427d2498027db0310b20bfe61e3c23e12b9619c Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Sun, 17 Nov 2024 15:17:07 -0800 Subject: [PATCH] Apply Clippy recommendations --- src/app.rs | 10 +++++----- src/components/left.rs | 13 ++++++------- src/components/popup.rs | 2 +- src/components/state.rs | 6 +----- src/system/disk.rs | 4 ---- src/system/diskpart.rs | 2 +- src/tasks.rs | 16 +++++++++------- 7 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/app.rs b/src/app.rs index a9fe77d..4322a1a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -98,7 +98,7 @@ impl App { action_tx, components: vec![ Box::new(Title::new()), - Box::new(FpsCounter::default()), + Box::new(FpsCounter::new()), Box::new(Left::new()), Box::new(Right::new()), Box::new(Footer::new()), @@ -298,12 +298,12 @@ impl App { Action::Select(one, two) => { match self.cur_mode { Mode::SelectDisks => { - self.disk_index_source = one.clone(); - self.disk_index_dest = two.clone(); + self.disk_index_source = one; + self.disk_index_dest = two; } Mode::SelectParts => { - self.part_index_boot = one.clone(); - self.part_index_os = two.clone(); + self.part_index_boot = one; + self.part_index_os = two; } _ => {} } diff --git a/src/components/left.rs b/src/components/left.rs index 62f4689..3d46716 100644 --- a/src/components/left.rs +++ b/src/components/left.rs @@ -105,14 +105,13 @@ impl Component for Left { | Mode::SelectTableType | Mode::SelectParts => { // Menu selection sections - let selection: Option; - match self.mode { - Mode::InstallDrivers => selection = self.list_drivers.selected(), - Mode::SelectDisks => selection = self.list_disks.selected(), - Mode::SelectTableType => selection = self.list_table_types.selected(), - Mode::SelectParts => selection = self.list_parts.selected(), + let selection: Option = match self.mode { + Mode::InstallDrivers => self.list_drivers.selected(), + Mode::SelectDisks => self.list_disks.selected(), + Mode::SelectTableType => self.list_table_types.selected(), + Mode::SelectParts => self.list_parts.selected(), _ => panic!("This shouldn't happen!"), - } + }; if let Some(index) = selection { if let Some(command_tx) = self.command_tx.clone() { let mut selection_one: Option = None; diff --git a/src/components/popup.rs b/src/components/popup.rs index df81bc3..54318a1 100644 --- a/src/components/popup.rs +++ b/src/components/popup.rs @@ -70,7 +70,7 @@ impl Component for Popup { Action::DismissPopup => self.popup_text.clear(), Action::DisplayPopup(new_type, new_text) => { self.popup_type = new_type; - self.popup_text = String::from(new_text); + self.popup_text = new_text; } Action::SetMode(mode) => { if mode == Mode::ScanDisks { diff --git a/src/components/state.rs b/src/components/state.rs index 7a4689d..b7b139c 100644 --- a/src/components/state.rs +++ b/src/components/state.rs @@ -36,11 +36,7 @@ impl StatefulList { } pub fn get_selected(&self) -> Option { - if let Some(i) = self.state.selected() { - Some(self.items[i].clone()) - } else { - None - } + self.state.selected().map(|i| self.items[i].clone()) } pub fn is_empty(&self) -> bool { diff --git a/src/system/disk.rs b/src/system/disk.rs index 6c49c01..46e010b 100644 --- a/src/system/disk.rs +++ b/src/system/disk.rs @@ -221,7 +221,6 @@ pub fn get_fake_disks() -> Vec { letter: String::from("Q"), part_type: String::from("EFI"), size: 272_629_760, - ..Default::default() }, Partition { id: 2, @@ -236,7 +235,6 @@ pub fn get_fake_disks() -> Vec { letter: String::from("V"), part_type: String::from("MS Basic Data"), size: 824_340_119_552, - ..Default::default() }, ], serial: "80085".to_string(), @@ -337,7 +335,6 @@ fn refresh_fake_disk_info() -> Vec { letter: String::from("S"), part_type: String::from("EFI"), size: 272_629_760, - ..Default::default() }, Partition { id: 2, @@ -353,7 +350,6 @@ fn refresh_fake_disk_info() -> Vec { letter: String::from("W"), part_type: String::from("MS Basic Data"), size: 824_340_119_552, - ..Default::default() }, ] } diff --git a/src/system/diskpart.rs b/src/system/diskpart.rs index 4475f93..554f607 100644 --- a/src/system/diskpart.rs +++ b/src/system/diskpart.rs @@ -290,7 +290,7 @@ pub fn parse_disk_numbers(contents: &str) -> Vec<&str> { disk_nums } -pub fn parse_partition_details(parts: &mut Vec, contents: &str) { +pub fn parse_partition_details(parts: &mut [Partition], contents: &str) { static RE_PAR: Lazy = Lazy::new(|| { Regex::new( r"Partition (\d+)\r?\nType\s*: (\S+)(\r?\n.*){5}\s*(Volume.*\r?\n.*\r?\n|There is no volume)(.*)", diff --git a/src/tasks.rs b/src/tasks.rs index 6168a03..1b10d97 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -144,7 +144,7 @@ impl Tasks { } } { let msg = format!("{:?}", &action); - if let Err(_) = task_tx.send(action) { + if task_tx.send(action).is_err() { panic!("Failed to send Action: {msg}"); } } @@ -159,12 +159,14 @@ impl Tasks { let script = String::from(script); self.handle = Some(thread::spawn(move || { let output = diskpart::run_script_raw(script.as_str()); - if !output.status.success() { - if let Err(_) = task_tx.send(Action::Error(String::from( - "Diskpart script returned an error", - ))) { - panic!("Failed to send Action: {task_str:?}"); - } + if !output.status.success() + && task_tx + .send(Action::Error(String::from( + "Diskpart script returned an error", + ))) + .is_err() + { + panic!("Failed to send Action: {task_str:?}"); } })); } else {