Address Clippy pedantic warnings for core
This commit is contained in:
parent
3c4603dc7b
commit
31d1391925
18 changed files with 74 additions and 30 deletions
|
|
@ -38,6 +38,7 @@ const VERSION_MESSAGE: &str = concat!(
|
|||
")"
|
||||
);
|
||||
|
||||
#[must_use]
|
||||
pub fn version() -> String {
|
||||
let author = clap::crate_authors!();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,12 +12,13 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
#![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;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ pub struct Footer {
|
|||
}
|
||||
|
||||
impl Footer {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
text: String::from("(q) to quit"),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ pub struct Left {
|
|||
}
|
||||
|
||||
impl Left {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
select_num: 0,
|
||||
|
|
|
|||
|
|
@ -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::<u8>() / 4 {
|
||||
0 => "FUN FACT\n\n\nComputers barely work.",
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ pub struct Right {
|
|||
}
|
||||
|
||||
impl Right {
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
selections: vec![None, None],
|
||||
|
|
|
|||
|
|
@ -31,14 +31,17 @@ impl<T: Clone> StatefulList<T> {
|
|||
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<T> {
|
||||
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<T: Clone> StatefulList<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn selected(&self) -> Option<usize> {
|
||||
self.state.selected()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ pub struct Title {
|
|||
}
|
||||
|
||||
impl Title {
|
||||
#[must_use]
|
||||
pub fn new(text: &str) -> Self {
|
||||
Self {
|
||||
text: String::from(text),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// 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
|
||||
|
||||
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<PathBuf> =
|
||||
env::var(format!("{}_DATA", PROJECT_NAME))
|
||||
env::var(format!("{PROJECT_NAME}_DATA"))
|
||||
.ok()
|
||||
.map(PathBuf::from);
|
||||
pub static ref CONFIG_FOLDER: Option<PathBuf> =
|
||||
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<Color> {
|
|||
.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))
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
#![allow(clippy::missing_errors_doc)]
|
||||
|
||||
use std::env;
|
||||
|
||||
use color_eyre::Result;
|
||||
|
|
|
|||
|
|
@ -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<Vec<usize>>,
|
||||
boot_os_indicies: &Option<Vec<usize>>,
|
||||
) -> Vec<DVLine> {
|
||||
let mut description: Vec<DVLine> = 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<DVLine> {
|
||||
let description: Vec<DVLine> = vec![
|
||||
DVLine {
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
#![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;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// 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 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<TaskType> {
|
||||
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<TaskType> {
|
||||
|
|
|
|||
|
|
@ -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<Partition> {
|
||||
self.parts.clone()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn num_parts(&self) -> usize {
|
||||
self.parts.len()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
#![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;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Deja-Vu. If not, see <https://www.gnu.org/licenses/>.
|
||||
//
|
||||
#![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<TaskResult>) -
|
|||
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
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// 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
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue