From 31d139192530f5eb0c7bf65d39ec5eac5944aa6e Mon Sep 17 00:00:00 2001
From: 2Shirt <2xShirt@gmail.com>
Date: Sat, 22 Mar 2025 21:23:03 -0700
Subject: [PATCH] Address Clippy pedantic warnings for core
---
core/src/cli.rs | 1 +
core/src/components.rs | 5 +++--
core/src/components/footer.rs | 1 +
core/src/components/fps.rs | 9 ++++++---
core/src/components/left.rs | 1 +
core/src/components/popup.rs | 2 ++
core/src/components/right.rs | 1 +
core/src/components/state.rs | 4 ++++
core/src/components/title.rs | 1 +
core/src/config.rs | 15 ++++++++++++---
core/src/errors.rs | 3 ++-
core/src/line.rs | 8 ++++++--
core/src/logging.rs | 5 +++--
core/src/system/boot.rs | 13 ++++++++-----
core/src/system/disk.rs | 3 +++
core/src/system/diskpart.rs | 5 +++--
core/src/tasks.rs | 15 +++++++++------
core/src/tui.rs | 12 ++++++++----
18 files changed, 74 insertions(+), 30 deletions(-)
diff --git a/core/src/cli.rs b/core/src/cli.rs
index f154dfe..b544d7b 100644
--- a/core/src/cli.rs
+++ b/core/src/cli.rs
@@ -38,6 +38,7 @@ const VERSION_MESSAGE: &str = concat!(
")"
);
+#[must_use]
pub fn version() -> String {
let author = clap::crate_authors!();
diff --git a/core/src/components.rs b/core/src/components.rs
index e46c56a..212155a 100644
--- a/core/src/components.rs
+++ b/core/src/components.rs
@@ -12,12 +12,13 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_errors_doc)]
+
use color_eyre::Result;
use crossterm::event::{KeyEvent, MouseEvent};
use ratatui::{
- layout::{Rect, Size},
Frame,
+ layout::{Rect, Size},
};
use tokio::sync::mpsc::UnboundedSender;
diff --git a/core/src/components/footer.rs b/core/src/components/footer.rs
index 2ab7406..25da73a 100644
--- a/core/src/components/footer.rs
+++ b/core/src/components/footer.rs
@@ -31,6 +31,7 @@ pub struct Footer {
}
impl Footer {
+ #[must_use]
pub fn new() -> Self {
Self {
text: String::from("(q) to quit"),
diff --git a/core/src/components/fps.rs b/core/src/components/fps.rs
index 32e4770..ffb70de 100644
--- a/core/src/components/fps.rs
+++ b/core/src/components/fps.rs
@@ -17,11 +17,11 @@ use std::time::Instant;
use color_eyre::Result;
use ratatui::{
+ Frame,
layout::{Constraint, Layout, Rect},
style::{Style, Stylize},
text::Span,
widgets::Paragraph,
- Frame,
};
use super::Component;
@@ -46,6 +46,7 @@ impl Default for FpsCounter {
}
impl FpsCounter {
+ #[must_use]
pub fn new() -> Self {
Self {
last_tick_update: Instant::now(),
@@ -57,24 +58,26 @@ impl FpsCounter {
}
}
+ #[allow(clippy::unnecessary_wraps)]
fn app_tick(&mut self) -> Result<()> {
self.tick_count += 1;
let now = Instant::now();
let elapsed = (now - self.last_tick_update).as_secs_f64();
if elapsed >= 1.0 {
- self.ticks_per_second = self.tick_count as f64 / elapsed;
+ self.ticks_per_second = f64::from(self.tick_count) / elapsed;
self.last_tick_update = now;
self.tick_count = 0;
}
Ok(())
}
+ #[allow(clippy::unnecessary_wraps)]
fn render_tick(&mut self) -> Result<()> {
self.frame_count += 1;
let now = Instant::now();
let elapsed = (now - self.last_frame_update).as_secs_f64();
if elapsed >= 1.0 {
- self.frames_per_second = self.frame_count as f64 / elapsed;
+ self.frames_per_second = f64::from(self.frame_count) / elapsed;
self.last_frame_update = now;
self.frame_count = 0;
}
diff --git a/core/src/components/left.rs b/core/src/components/left.rs
index 0f7112f..e83a6e1 100644
--- a/core/src/components/left.rs
+++ b/core/src/components/left.rs
@@ -37,6 +37,7 @@ pub struct Left {
}
impl Left {
+ #[must_use]
pub fn new() -> Self {
Self {
select_num: 0,
diff --git a/core/src/components/popup.rs b/core/src/components/popup.rs
index 4b951a7..742f9e0 100644
--- a/core/src/components/popup.rs
+++ b/core/src/components/popup.rs
@@ -43,6 +43,7 @@ pub struct Popup {
}
impl Popup {
+ #[must_use]
pub fn new() -> Self {
Self::default()
}
@@ -97,6 +98,7 @@ impl Component for Popup {
}
}
+#[must_use]
pub fn fortune() -> String {
String::from(match random::() / 4 {
0 => "FUN FACT\n\n\nComputers barely work.",
diff --git a/core/src/components/right.rs b/core/src/components/right.rs
index 04a8d16..e36d3bc 100644
--- a/core/src/components/right.rs
+++ b/core/src/components/right.rs
@@ -37,6 +37,7 @@ pub struct Right {
}
impl Right {
+ #[must_use]
pub fn new() -> Self {
Self {
selections: vec![None, None],
diff --git a/core/src/components/state.rs b/core/src/components/state.rs
index d2862a9..a031fea 100644
--- a/core/src/components/state.rs
+++ b/core/src/components/state.rs
@@ -31,14 +31,17 @@ impl StatefulList {
self.items.clear();
}
+ #[must_use]
pub fn get(&self, index: usize) -> Option<&T> {
self.items.get(index)
}
+ #[must_use]
pub fn get_selected(&self) -> Option {
self.state.selected().map(|i| self.items[i].clone())
}
+ #[must_use]
pub fn is_empty(&self) -> bool {
self.items.is_empty()
}
@@ -51,6 +54,7 @@ impl StatefulList {
}
}
+ #[must_use]
pub fn selected(&self) -> Option {
self.state.selected()
}
diff --git a/core/src/components/title.rs b/core/src/components/title.rs
index dd5a09a..9c4a95b 100644
--- a/core/src/components/title.rs
+++ b/core/src/components/title.rs
@@ -31,6 +31,7 @@ pub struct Title {
}
impl Title {
+ #[must_use]
pub fn new(text: &str) -> Self {
Self {
text: String::from(text),
diff --git a/core/src/config.rs b/core/src/config.rs
index 105b705..0a97126 100644
--- a/core/src/config.rs
+++ b/core/src/config.rs
@@ -12,7 +12,9 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_errors_doc)]
+#![allow(clippy::missing_panics_doc)]
+#![allow(clippy::ref_option)]
#![allow(dead_code)] // Remove this once you start using the code
use std::{collections::HashMap, env, path::PathBuf};
@@ -58,11 +60,11 @@ 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 =
- env::var(format!("{}_DATA", PROJECT_NAME))
+ env::var(format!("{PROJECT_NAME}_DATA"))
.ok()
.map(PathBuf::from);
pub static ref CONFIG_FOLDER: Option =
- env::var(format!("{}_CONFIG", PROJECT_NAME))
+ env::var(format!("{PROJECT_NAME}_CONFIG"))
.ok()
.map(PathBuf::from);
}
@@ -126,6 +128,7 @@ impl Config {
}
}
+#[must_use]
pub fn get_data_dir() -> PathBuf {
let directory = if let Some(s) = DATA_FOLDER.clone() {
s
@@ -137,6 +140,7 @@ pub fn get_data_dir() -> PathBuf {
directory
}
+#[must_use]
pub fn get_config_dir() -> PathBuf {
let directory = if let Some(s) = CONFIG_FOLDER.clone() {
s
@@ -258,6 +262,7 @@ fn parse_key_code_with_modifiers(
Ok(KeyEvent::new(c, modifiers))
}
+#[must_use]
pub fn key_event_to_string(key_event: &KeyEvent) -> String {
let char;
let key_code = match key_event.code {
@@ -373,6 +378,7 @@ impl<'de> Deserialize<'de> for Styles {
}
}
+#[must_use]
pub fn parse_style(line: &str) -> Style {
let (foreground, background) =
line.split_at(line.to_lowercase().find("on ").unwrap_or(line.len()));
@@ -435,8 +441,11 @@ fn parse_color(s: &str) -> Option {
.unwrap_or_default();
Some(Color::Indexed(c))
} else if s.contains("rgb") {
+ #[allow(clippy::cast_possible_truncation)]
let red = (s.as_bytes()[3] as char).to_digit(10).unwrap_or_default() as u8;
+ #[allow(clippy::cast_possible_truncation)]
let green = (s.as_bytes()[4] as char).to_digit(10).unwrap_or_default() as u8;
+ #[allow(clippy::cast_possible_truncation)]
let blue = (s.as_bytes()[5] as char).to_digit(10).unwrap_or_default() as u8;
let c = 16 + red * 36 + green * 6 + blue;
Some(Color::Indexed(c))
diff --git a/core/src/errors.rs b/core/src/errors.rs
index 6285edc..22572c5 100644
--- a/core/src/errors.rs
+++ b/core/src/errors.rs
@@ -12,7 +12,8 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_errors_doc)]
+
use std::env;
use color_eyre::Result;
diff --git a/core/src/line.rs b/core/src/line.rs
index 5a70312..375f1f4 100644
--- a/core/src/line.rs
+++ b/core/src/line.rs
@@ -30,6 +30,7 @@ pub struct DVLine {
impl DVLine {
/// Convert to Line with colored span(s)
+ #[must_use]
pub fn as_line(&self) -> Line {
let mut spans = Vec::new();
zip(self.line_parts.clone(), self.line_colors.clone())
@@ -37,6 +38,7 @@ impl DVLine {
Line::from(spans)
}
+ #[must_use]
pub fn blank() -> Self {
Self {
line_parts: vec![String::new()],
@@ -45,9 +47,10 @@ impl DVLine {
}
}
+#[must_use]
pub fn get_disk_description_right(
disk: &Disk,
- boot_os_indicies: Option>,
+ boot_os_indicies: &Option>,
) -> Vec {
let mut description: Vec = vec![
DVLine {
@@ -76,7 +79,7 @@ pub fn get_disk_description_right(
.for_each(|(index, line)| {
let mut line_parts = vec![line.clone()];
let mut line_colors = vec![Color::Reset];
- if let Some(indicies) = &boot_os_indicies {
+ if let Some(indicies) = boot_os_indicies {
let boot_index = indicies.first();
if boot_index.is_some_and(|i| i == &index) {
line_parts.push(String::from(" <-- Boot Partition"));
@@ -96,6 +99,7 @@ pub fn get_disk_description_right(
description
}
+#[must_use]
pub fn get_part_description(part: &Partition) -> Vec {
let description: Vec = vec![
DVLine {
diff --git a/core/src/logging.rs b/core/src/logging.rs
index 02c8b3a..c3bde74 100644
--- a/core/src/logging.rs
+++ b/core/src/logging.rs
@@ -12,10 +12,11 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_errors_doc)]
+
use color_eyre::Result;
use tracing_error::ErrorLayer;
-use tracing_subscriber::{fmt, prelude::*, EnvFilter};
+use tracing_subscriber::{EnvFilter, fmt, prelude::*};
use crate::config;
diff --git a/core/src/system/boot.rs b/core/src/system/boot.rs
index 3a87d2d..d8daa44 100644
--- a/core/src/system/boot.rs
+++ b/core/src/system/boot.rs
@@ -12,7 +12,9 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_errors_doc)]
+#![allow(clippy::missing_panics_doc)]
+
use super::{disk::PartitionTableType, drivers::Driver};
use crate::tasks::TaskType;
use color_eyre::Result;
@@ -25,11 +27,12 @@ pub enum SafeMode {
Enable,
}
+#[must_use]
pub fn configure_disk(
letter_boot: &str,
letter_os: &str,
system32: &str,
- table_type: PartitionTableType,
+ table_type: &PartitionTableType,
) -> Vec {
let mut tasks = Vec::new();
@@ -49,7 +52,7 @@ pub fn configure_disk(
));
// Update boot sector (for legacy setups)
- if table_type == PartitionTableType::Legacy {
+ if *table_type == PartitionTableType::Legacy {
tasks.push(TaskType::CommandWait(
PathBuf::from(format!("{system32}/bootsect.exe")),
vec![
@@ -63,7 +66,7 @@ pub fn configure_disk(
// Lock in safe mode
tasks.push(
- set_mode(letter_boot, SafeMode::Enable, system32, &table_type)
+ set_mode(letter_boot, &SafeMode::Enable, system32, table_type)
.expect("Failed to create set_mode task."),
);
@@ -87,7 +90,7 @@ pub fn inject_driver(driver: &Driver, letter_os: &str, system32: &str) -> Result
pub fn set_mode(
letter_boot: &str,
- mode: SafeMode,
+ mode: &SafeMode,
system32: &str,
table_type: &PartitionTableType,
) -> Result {
diff --git a/core/src/system/disk.rs b/core/src/system/disk.rs
index 3450add..84a3d5e 100644
--- a/core/src/system/disk.rs
+++ b/core/src/system/disk.rs
@@ -67,6 +67,7 @@ impl Disk {
}
}
+ #[must_use]
pub fn get_part_letter(&self, part_index: usize) -> String {
// Used to get Boot and OS letters
if let Some(part) = self.parts.get(part_index) {
@@ -76,10 +77,12 @@ impl Disk {
}
}
+ #[must_use]
pub fn get_parts(&self) -> Vec {
self.parts.clone()
}
+ #[must_use]
pub fn num_parts(&self) -> usize {
self.parts.len()
}
diff --git a/core/src/system/diskpart.rs b/core/src/system/diskpart.rs
index ae1c97a..fa3649d 100644
--- a/core/src/system/diskpart.rs
+++ b/core/src/system/diskpart.rs
@@ -12,7 +12,8 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_panics_doc)]
+
use std::{
collections::HashMap,
fs::File,
@@ -26,7 +27,7 @@ use tempfile::tempdir;
use tracing::{info, warn};
use crate::system::disk::{
- get_disk_serial_number, string_to_bytes, Disk, Partition, PartitionTableType,
+ Disk, Partition, PartitionTableType, get_disk_serial_number, string_to_bytes,
};
static DEFAULT_MAX_DISKS: usize = 8;
diff --git a/core/src/tasks.rs b/core/src/tasks.rs
index dde4d36..ca9ba66 100644
--- a/core/src/tasks.rs
+++ b/core/src/tasks.rs
@@ -12,7 +12,8 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_errors_doc)]
+#![allow(clippy::missing_panics_doc)]
use std::{
collections::VecDeque,
@@ -80,6 +81,7 @@ pub struct Task {
}
impl Task {
+ #[must_use]
pub fn new(task_type: TaskType) -> Task {
Task {
handle: None,
@@ -122,6 +124,7 @@ impl Tasks {
self.task_list.push_back(Task::new(task_type));
}
+ #[must_use]
pub fn idle(&self) -> bool {
self.cur_handle.is_none()
}
@@ -190,7 +193,7 @@ impl Tasks {
self.cur_handle = Some(thread::spawn(move || {
let mut disks = disk_list_arc.lock().unwrap();
- *disks = disk::get_disks()
+ *disks = disk::get_disks();
}));
}
TaskType::Sleep => {
@@ -257,8 +260,8 @@ fn run_task_command(
.expect("Failed to propegate error?");
}
Ok(output) => {
- let stderr = parse_bytes_as_str(output.stderr.to_owned());
- let stdout = parse_bytes_as_str(output.stdout.to_owned());
+ let stderr = parse_bytes_as_str(output.stderr.clone());
+ let stdout = parse_bytes_as_str(output.stdout.clone());
let task_result = TaskResult::Output(stdout, stderr, output.status.success());
let err_str = format!("Failed to send TaskResult: {:?}", &task_result);
task_tx
@@ -278,8 +281,8 @@ fn run_task_diskpart(script: &str, task_tx: mpsc::UnboundedSender) -
let script = script.to_owned();
thread::spawn(move || {
let output = diskpart::run_script_raw(&script);
- let stderr = parse_bytes_as_str(output.stderr.to_owned());
- let stdout = parse_bytes_as_str(output.stdout.to_owned());
+ let stderr = parse_bytes_as_str(output.stderr.clone());
+ let stdout = parse_bytes_as_str(output.stdout.clone());
let task_result = TaskResult::Output(stdout, stderr, output.status.success());
let err_str = format!("Failed to send TaskResult: {:?}", &task_result);
task_tx
diff --git a/core/src/tui.rs b/core/src/tui.rs
index cf563b0..071ea01 100644
--- a/core/src/tui.rs
+++ b/core/src/tui.rs
@@ -12,11 +12,11 @@
//
// You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see .
-//
+#![allow(clippy::missing_errors_doc)]
#![allow(dead_code)] // Remove this once you start using the code
use std::{
- io::{stdout, Stdout},
+ io::{Stdout, stdout},
ops::{Deref, DerefMut},
time::Duration,
};
@@ -85,21 +85,25 @@ impl Tui {
})
}
+ #[must_use]
pub fn tick_rate(mut self, tick_rate: f64) -> Self {
self.tick_rate = tick_rate;
self
}
+ #[must_use]
pub fn frame_rate(mut self, frame_rate: f64) -> Self {
self.frame_rate = frame_rate;
self
}
+ #[must_use]
pub fn mouse(mut self, mouse: bool) -> Self {
self.mouse = mouse;
self
}
+ #[must_use]
pub fn paste(mut self, paste: bool) -> Self {
self.paste = paste;
self
@@ -135,7 +139,7 @@ impl Tui {
.expect("failed to send init event");
loop {
let event = tokio::select! {
- _ = cancellation_token.cancelled() => {
+ () = cancellation_token.cancelled() => {
break;
}
_ = tick_interval.tick() => Event::Tick,
@@ -148,7 +152,7 @@ impl Tui {
CrosstermEvent::FocusLost => Event::FocusLost,
CrosstermEvent::FocusGained => Event::FocusGained,
CrosstermEvent::Paste(s) => Event::Paste(s),
- _ => continue, // ignore other events
+ CrosstermEvent::Key(_) => continue, // ignore other events
}
Some(Err(_)) => Event::Error,
None => break, // the event stream has stopped and will not produce any more events