Address Clippy pedantic warnings for core

This commit is contained in:
2Shirt 2025-03-22 21:23:03 -07:00
parent 3c4603dc7b
commit 31d1391925
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
18 changed files with 74 additions and 30 deletions

View file

@ -38,6 +38,7 @@ const VERSION_MESSAGE: &str = concat!(
")" ")"
); );
#[must_use]
pub fn version() -> String { pub fn version() -> String {
let author = clap::crate_authors!(); let author = clap::crate_authors!();

View file

@ -12,12 +12,13 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![allow(clippy::missing_errors_doc)]
use color_eyre::Result; use color_eyre::Result;
use crossterm::event::{KeyEvent, MouseEvent}; use crossterm::event::{KeyEvent, MouseEvent};
use ratatui::{ use ratatui::{
layout::{Rect, Size},
Frame, Frame,
layout::{Rect, Size},
}; };
use tokio::sync::mpsc::UnboundedSender; use tokio::sync::mpsc::UnboundedSender;

View file

@ -31,6 +31,7 @@ pub struct Footer {
} }
impl Footer { impl Footer {
#[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
text: String::from("(q) to quit"), text: String::from("(q) to quit"),

View file

@ -17,11 +17,11 @@ use std::time::Instant;
use color_eyre::Result; use color_eyre::Result;
use ratatui::{ use ratatui::{
Frame,
layout::{Constraint, Layout, Rect}, layout::{Constraint, Layout, Rect},
style::{Style, Stylize}, style::{Style, Stylize},
text::Span, text::Span,
widgets::Paragraph, widgets::Paragraph,
Frame,
}; };
use super::Component; use super::Component;
@ -46,6 +46,7 @@ impl Default for FpsCounter {
} }
impl FpsCounter { impl FpsCounter {
#[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
last_tick_update: Instant::now(), last_tick_update: Instant::now(),
@ -57,24 +58,26 @@ impl FpsCounter {
} }
} }
#[allow(clippy::unnecessary_wraps)]
fn app_tick(&mut self) -> Result<()> { fn app_tick(&mut self) -> Result<()> {
self.tick_count += 1; self.tick_count += 1;
let now = Instant::now(); let now = Instant::now();
let elapsed = (now - self.last_tick_update).as_secs_f64(); let elapsed = (now - self.last_tick_update).as_secs_f64();
if elapsed >= 1.0 { 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.last_tick_update = now;
self.tick_count = 0; self.tick_count = 0;
} }
Ok(()) Ok(())
} }
#[allow(clippy::unnecessary_wraps)]
fn render_tick(&mut self) -> Result<()> { fn render_tick(&mut self) -> Result<()> {
self.frame_count += 1; self.frame_count += 1;
let now = Instant::now(); let now = Instant::now();
let elapsed = (now - self.last_frame_update).as_secs_f64(); let elapsed = (now - self.last_frame_update).as_secs_f64();
if elapsed >= 1.0 { 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.last_frame_update = now;
self.frame_count = 0; self.frame_count = 0;
} }

View file

@ -37,6 +37,7 @@ pub struct Left {
} }
impl Left { impl Left {
#[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
select_num: 0, select_num: 0,

View file

@ -43,6 +43,7 @@ pub struct Popup {
} }
impl Popup { impl Popup {
#[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self::default()
} }
@ -97,6 +98,7 @@ impl Component for Popup {
} }
} }
#[must_use]
pub fn fortune() -> String { pub fn fortune() -> String {
String::from(match random::<u8>() / 4 { String::from(match random::<u8>() / 4 {
0 => "FUN FACT\n\n\nComputers barely work.", 0 => "FUN FACT\n\n\nComputers barely work.",

View file

@ -37,6 +37,7 @@ pub struct Right {
} }
impl Right { impl Right {
#[must_use]
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
selections: vec![None, None], selections: vec![None, None],

View file

@ -31,14 +31,17 @@ impl<T: Clone> StatefulList<T> {
self.items.clear(); self.items.clear();
} }
#[must_use]
pub fn get(&self, index: usize) -> Option<&T> { pub fn get(&self, index: usize) -> Option<&T> {
self.items.get(index) self.items.get(index)
} }
#[must_use]
pub fn get_selected(&self) -> Option<T> { pub fn get_selected(&self) -> Option<T> {
self.state.selected().map(|i| self.items[i].clone()) self.state.selected().map(|i| self.items[i].clone())
} }
#[must_use]
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.items.is_empty() self.items.is_empty()
} }
@ -51,6 +54,7 @@ impl<T: Clone> StatefulList<T> {
} }
} }
#[must_use]
pub fn selected(&self) -> Option<usize> { pub fn selected(&self) -> Option<usize> {
self.state.selected() self.state.selected()
} }

View file

@ -31,6 +31,7 @@ pub struct Title {
} }
impl Title { impl Title {
#[must_use]
pub fn new(text: &str) -> Self { pub fn new(text: &str) -> Self {
Self { Self {
text: String::from(text), text: String::from(text),

View file

@ -12,7 +12,9 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![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 #![allow(dead_code)] // Remove this once you start using the code
use std::{collections::HashMap, env, path::PathBuf}; use std::{collections::HashMap, env, path::PathBuf};
@ -58,11 +60,11 @@ pub static PROJECT_NAME: &str = "DEJA-VU";
lazy_static! { lazy_static! {
//pub static ref PROJECT_NAME: String = env!("CARGO_PKG_NAME").to_uppercase().to_string(); //pub static ref PROJECT_NAME: String = env!("CARGO_PKG_NAME").to_uppercase().to_string();
pub static ref DATA_FOLDER: Option<PathBuf> = pub static ref DATA_FOLDER: Option<PathBuf> =
env::var(format!("{}_DATA", PROJECT_NAME)) env::var(format!("{PROJECT_NAME}_DATA"))
.ok() .ok()
.map(PathBuf::from); .map(PathBuf::from);
pub static ref CONFIG_FOLDER: Option<PathBuf> = pub static ref CONFIG_FOLDER: Option<PathBuf> =
env::var(format!("{}_CONFIG", PROJECT_NAME)) env::var(format!("{PROJECT_NAME}_CONFIG"))
.ok() .ok()
.map(PathBuf::from); .map(PathBuf::from);
} }
@ -126,6 +128,7 @@ impl Config {
} }
} }
#[must_use]
pub fn get_data_dir() -> PathBuf { pub fn get_data_dir() -> PathBuf {
let directory = if let Some(s) = DATA_FOLDER.clone() { let directory = if let Some(s) = DATA_FOLDER.clone() {
s s
@ -137,6 +140,7 @@ pub fn get_data_dir() -> PathBuf {
directory directory
} }
#[must_use]
pub fn get_config_dir() -> PathBuf { pub fn get_config_dir() -> PathBuf {
let directory = if let Some(s) = CONFIG_FOLDER.clone() { let directory = if let Some(s) = CONFIG_FOLDER.clone() {
s s
@ -258,6 +262,7 @@ fn parse_key_code_with_modifiers(
Ok(KeyEvent::new(c, modifiers)) Ok(KeyEvent::new(c, modifiers))
} }
#[must_use]
pub fn key_event_to_string(key_event: &KeyEvent) -> String { pub fn key_event_to_string(key_event: &KeyEvent) -> String {
let char; let char;
let key_code = match key_event.code { 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 { pub fn parse_style(line: &str) -> Style {
let (foreground, background) = let (foreground, background) =
line.split_at(line.to_lowercase().find("on ").unwrap_or(line.len())); line.split_at(line.to_lowercase().find("on ").unwrap_or(line.len()));
@ -435,8 +441,11 @@ fn parse_color(s: &str) -> Option<Color> {
.unwrap_or_default(); .unwrap_or_default();
Some(Color::Indexed(c)) Some(Color::Indexed(c))
} else if s.contains("rgb") { } 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; 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; 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 blue = (s.as_bytes()[5] as char).to_digit(10).unwrap_or_default() as u8;
let c = 16 + red * 36 + green * 6 + blue; let c = 16 + red * 36 + green * 6 + blue;
Some(Color::Indexed(c)) Some(Color::Indexed(c))

View file

@ -12,7 +12,8 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![allow(clippy::missing_errors_doc)]
use std::env; use std::env;
use color_eyre::Result; use color_eyre::Result;

View file

@ -30,6 +30,7 @@ pub struct DVLine {
impl DVLine { impl DVLine {
/// Convert to Line with colored span(s) /// Convert to Line with colored span(s)
#[must_use]
pub fn as_line(&self) -> Line { pub fn as_line(&self) -> Line {
let mut spans = Vec::new(); let mut spans = Vec::new();
zip(self.line_parts.clone(), self.line_colors.clone()) zip(self.line_parts.clone(), self.line_colors.clone())
@ -37,6 +38,7 @@ impl DVLine {
Line::from(spans) Line::from(spans)
} }
#[must_use]
pub fn blank() -> Self { pub fn blank() -> Self {
Self { Self {
line_parts: vec![String::new()], line_parts: vec![String::new()],
@ -45,9 +47,10 @@ impl DVLine {
} }
} }
#[must_use]
pub fn get_disk_description_right( pub fn get_disk_description_right(
disk: &Disk, disk: &Disk,
boot_os_indicies: Option<Vec<usize>>, boot_os_indicies: &Option<Vec<usize>>,
) -> Vec<DVLine> { ) -> Vec<DVLine> {
let mut description: Vec<DVLine> = vec![ let mut description: Vec<DVLine> = vec![
DVLine { DVLine {
@ -76,7 +79,7 @@ pub fn get_disk_description_right(
.for_each(|(index, line)| { .for_each(|(index, line)| {
let mut line_parts = vec![line.clone()]; let mut line_parts = vec![line.clone()];
let mut line_colors = vec![Color::Reset]; 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(); let boot_index = indicies.first();
if boot_index.is_some_and(|i| i == &index) { if boot_index.is_some_and(|i| i == &index) {
line_parts.push(String::from(" <-- Boot Partition")); line_parts.push(String::from(" <-- Boot Partition"));
@ -96,6 +99,7 @@ pub fn get_disk_description_right(
description description
} }
#[must_use]
pub fn get_part_description(part: &Partition) -> Vec<DVLine> { pub fn get_part_description(part: &Partition) -> Vec<DVLine> {
let description: Vec<DVLine> = vec![ let description: Vec<DVLine> = vec![
DVLine { DVLine {

View file

@ -12,10 +12,11 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![allow(clippy::missing_errors_doc)]
use color_eyre::Result; use color_eyre::Result;
use tracing_error::ErrorLayer; use tracing_error::ErrorLayer;
use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use tracing_subscriber::{EnvFilter, fmt, prelude::*};
use crate::config; use crate::config;

View file

@ -12,7 +12,9 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
use super::{disk::PartitionTableType, drivers::Driver}; use super::{disk::PartitionTableType, drivers::Driver};
use crate::tasks::TaskType; use crate::tasks::TaskType;
use color_eyre::Result; use color_eyre::Result;
@ -25,11 +27,12 @@ pub enum SafeMode {
Enable, Enable,
} }
#[must_use]
pub fn configure_disk( pub fn configure_disk(
letter_boot: &str, letter_boot: &str,
letter_os: &str, letter_os: &str,
system32: &str, system32: &str,
table_type: PartitionTableType, table_type: &PartitionTableType,
) -> Vec<TaskType> { ) -> Vec<TaskType> {
let mut tasks = Vec::new(); let mut tasks = Vec::new();
@ -49,7 +52,7 @@ pub fn configure_disk(
)); ));
// Update boot sector (for legacy setups) // Update boot sector (for legacy setups)
if table_type == PartitionTableType::Legacy { if *table_type == PartitionTableType::Legacy {
tasks.push(TaskType::CommandWait( tasks.push(TaskType::CommandWait(
PathBuf::from(format!("{system32}/bootsect.exe")), PathBuf::from(format!("{system32}/bootsect.exe")),
vec![ vec![
@ -63,7 +66,7 @@ pub fn configure_disk(
// Lock in safe mode // Lock in safe mode
tasks.push( 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."), .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( pub fn set_mode(
letter_boot: &str, letter_boot: &str,
mode: SafeMode, mode: &SafeMode,
system32: &str, system32: &str,
table_type: &PartitionTableType, table_type: &PartitionTableType,
) -> Result<TaskType> { ) -> Result<TaskType> {

View file

@ -67,6 +67,7 @@ impl Disk {
} }
} }
#[must_use]
pub fn get_part_letter(&self, part_index: usize) -> String { pub fn get_part_letter(&self, part_index: usize) -> String {
// Used to get Boot and OS letters // Used to get Boot and OS letters
if let Some(part) = self.parts.get(part_index) { if let Some(part) = self.parts.get(part_index) {
@ -76,10 +77,12 @@ impl Disk {
} }
} }
#[must_use]
pub fn get_parts(&self) -> Vec<Partition> { pub fn get_parts(&self) -> Vec<Partition> {
self.parts.clone() self.parts.clone()
} }
#[must_use]
pub fn num_parts(&self) -> usize { pub fn num_parts(&self) -> usize {
self.parts.len() self.parts.len()
} }

View file

@ -12,7 +12,8 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![allow(clippy::missing_panics_doc)]
use std::{ use std::{
collections::HashMap, collections::HashMap,
fs::File, fs::File,
@ -26,7 +27,7 @@ use tempfile::tempdir;
use tracing::{info, warn}; use tracing::{info, warn};
use crate::system::disk::{ 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; static DEFAULT_MAX_DISKS: usize = 8;

View file

@ -12,7 +12,8 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![allow(clippy::missing_errors_doc)]
#![allow(clippy::missing_panics_doc)]
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
@ -80,6 +81,7 @@ pub struct Task {
} }
impl Task { impl Task {
#[must_use]
pub fn new(task_type: TaskType) -> Task { pub fn new(task_type: TaskType) -> Task {
Task { Task {
handle: None, handle: None,
@ -122,6 +124,7 @@ impl Tasks {
self.task_list.push_back(Task::new(task_type)); self.task_list.push_back(Task::new(task_type));
} }
#[must_use]
pub fn idle(&self) -> bool { pub fn idle(&self) -> bool {
self.cur_handle.is_none() self.cur_handle.is_none()
} }
@ -190,7 +193,7 @@ impl Tasks {
self.cur_handle = Some(thread::spawn(move || { self.cur_handle = Some(thread::spawn(move || {
let mut disks = disk_list_arc.lock().unwrap(); let mut disks = disk_list_arc.lock().unwrap();
*disks = disk::get_disks() *disks = disk::get_disks();
})); }));
} }
TaskType::Sleep => { TaskType::Sleep => {
@ -257,8 +260,8 @@ fn run_task_command(
.expect("Failed to propegate error?"); .expect("Failed to propegate error?");
} }
Ok(output) => { Ok(output) => {
let stderr = parse_bytes_as_str(output.stderr.to_owned()); let stderr = parse_bytes_as_str(output.stderr.clone());
let stdout = parse_bytes_as_str(output.stdout.to_owned()); let stdout = parse_bytes_as_str(output.stdout.clone());
let task_result = TaskResult::Output(stdout, stderr, output.status.success()); let task_result = TaskResult::Output(stdout, stderr, output.status.success());
let err_str = format!("Failed to send TaskResult: {:?}", &task_result); let err_str = format!("Failed to send TaskResult: {:?}", &task_result);
task_tx task_tx
@ -278,8 +281,8 @@ fn run_task_diskpart(script: &str, task_tx: mpsc::UnboundedSender<TaskResult>) -
let script = script.to_owned(); let script = script.to_owned();
thread::spawn(move || { thread::spawn(move || {
let output = diskpart::run_script_raw(&script); let output = diskpart::run_script_raw(&script);
let stderr = parse_bytes_as_str(output.stderr.to_owned()); let stderr = parse_bytes_as_str(output.stderr.clone());
let stdout = parse_bytes_as_str(output.stdout.to_owned()); let stdout = parse_bytes_as_str(output.stdout.clone());
let task_result = TaskResult::Output(stdout, stderr, output.status.success()); let task_result = TaskResult::Output(stdout, stderr, output.status.success());
let err_str = format!("Failed to send TaskResult: {:?}", &task_result); let err_str = format!("Failed to send TaskResult: {:?}", &task_result);
task_tx task_tx

View file

@ -12,11 +12,11 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>. // along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
// #![allow(clippy::missing_errors_doc)]
#![allow(dead_code)] // Remove this once you start using the code #![allow(dead_code)] // Remove this once you start using the code
use std::{ use std::{
io::{stdout, Stdout}, io::{Stdout, stdout},
ops::{Deref, DerefMut}, ops::{Deref, DerefMut},
time::Duration, time::Duration,
}; };
@ -85,21 +85,25 @@ impl Tui {
}) })
} }
#[must_use]
pub fn tick_rate(mut self, tick_rate: f64) -> Self { pub fn tick_rate(mut self, tick_rate: f64) -> Self {
self.tick_rate = tick_rate; self.tick_rate = tick_rate;
self self
} }
#[must_use]
pub fn frame_rate(mut self, frame_rate: f64) -> Self { pub fn frame_rate(mut self, frame_rate: f64) -> Self {
self.frame_rate = frame_rate; self.frame_rate = frame_rate;
self self
} }
#[must_use]
pub fn mouse(mut self, mouse: bool) -> Self { pub fn mouse(mut self, mouse: bool) -> Self {
self.mouse = mouse; self.mouse = mouse;
self self
} }
#[must_use]
pub fn paste(mut self, paste: bool) -> Self { pub fn paste(mut self, paste: bool) -> Self {
self.paste = paste; self.paste = paste;
self self
@ -135,7 +139,7 @@ impl Tui {
.expect("failed to send init event"); .expect("failed to send init event");
loop { loop {
let event = tokio::select! { let event = tokio::select! {
_ = cancellation_token.cancelled() => { () = cancellation_token.cancelled() => {
break; break;
} }
_ = tick_interval.tick() => Event::Tick, _ = tick_interval.tick() => Event::Tick,
@ -148,7 +152,7 @@ impl Tui {
CrosstermEvent::FocusLost => Event::FocusLost, CrosstermEvent::FocusLost => Event::FocusLost,
CrosstermEvent::FocusGained => Event::FocusGained, CrosstermEvent::FocusGained => Event::FocusGained,
CrosstermEvent::Paste(s) => Event::Paste(s), CrosstermEvent::Paste(s) => Event::Paste(s),
_ => continue, // ignore other events CrosstermEvent::Key(_) => continue, // ignore other events
} }
Some(Err(_)) => Event::Error, Some(Err(_)) => Event::Error,
None => break, // the event stream has stopped and will not produce any more events None => break, // the event stream has stopped and will not produce any more events