From f7d070f9440e86bc04cc2304232ec3cf76b1eed0 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 21 Feb 2025 21:12:08 -0500 Subject: [PATCH] refactor: somewhat migrate to Rust 2024 edition (#1681) * refactor: try bumping to rust 2024 edition * now run nightly fmt * fix some macos changes * only apply a few of these settings --- build.rs | 2 +- rustfmt.toml | 1 + src/app/data/process.rs | 3 +- src/app/data/store.rs | 7 +- src/app/layout_manager.rs | 19 ++--- src/app/process_killer.rs | 8 +- src/app/states.rs | 4 +- src/canvas.rs | 10 +-- src/canvas/components/data_table/draw.rs | 4 +- src/canvas/components/time_graph.rs | 5 +- .../components/time_graph/time_chart.rs | 6 +- .../time_graph/time_chart/canvas.rs | 2 +- .../time_graph/time_chart/points.rs | 2 +- src/canvas/components/widget_carousel.rs | 4 +- src/canvas/dialogs/dd_dialog.rs | 4 +- src/canvas/dialogs/help_dialog.rs | 4 +- src/canvas/widgets/battery_display.rs | 4 +- src/canvas/widgets/cpu_basic.rs | 4 +- src/canvas/widgets/cpu_graph.rs | 16 ++-- src/canvas/widgets/disk_table.rs | 4 +- src/canvas/widgets/mem_basic.rs | 4 +- src/canvas/widgets/mem_graph.rs | 6 +- src/canvas/widgets/network_basic.rs | 4 +- src/canvas/widgets/network_graph.rs | 10 +-- src/canvas/widgets/process_table.rs | 4 +- src/canvas/widgets/temperature_table.rs | 4 +- src/collection/amd.rs | 12 +-- src/collection/batteries.rs | 2 +- src/collection/disks/freebsd.rs | 4 +- src/collection/disks/other.rs | 2 +- src/collection/disks/unix.rs | 2 +- .../disks/unix/macos/io_kit/bindings.rs | 7 +- .../disks/unix/macos/io_kit/io_disks.rs | 2 +- .../disks/unix/macos/io_kit/io_object.rs | 2 +- src/collection/disks/unix/other/bindings.rs | 5 +- src/collection/disks/unix/other/partition.rs | 2 +- src/collection/disks/windows.rs | 4 +- src/collection/disks/windows/bindings.rs | 8 +- src/collection/disks/zfs_io_counters.rs | 6 +- src/collection/nvidia.rs | 2 +- src/collection/processes.rs | 2 +- src/collection/processes/freebsd.rs | 2 +- src/collection/processes/linux/mod.rs | 4 +- .../processes/macos/sysctl_bindings.rs | 6 +- src/collection/processes/unix/process_ext.rs | 4 +- src/collection/processes/windows.rs | 4 +- src/event.rs | 2 +- src/lib.rs | 34 ++++---- src/options.rs | 15 ++-- src/options/config/style.rs | 2 +- src/options/config/style/themes/gruvbox.rs | 2 +- src/options/config/style/themes/nord.rs | 2 +- src/options/config/style/utils.rs | 84 +++++++++++-------- src/options/config/style/widgets.rs | 2 +- src/utils/general.rs | 12 +-- src/widgets/cpu_graph.rs | 2 +- src/widgets/disk_table.rs | 2 +- src/widgets/process_table.rs | 4 +- src/widgets/process_table/process_data.rs | 9 +- src/widgets/process_table/query.rs | 2 +- src/widgets/temperature_table.rs | 2 +- tests/integration/util.rs | 2 +- 62 files changed, 207 insertions(+), 198 deletions(-) diff --git a/build.rs b/build.rs index 42a23eb3..efae0a0e 100644 --- a/build.rs +++ b/build.rs @@ -10,7 +10,7 @@ use std::{ }; use clap::{Command, CommandFactory}; -use clap_complete::{generate_to, shells::Shell, Generator}; +use clap_complete::{Generator, generate_to, shells::Shell}; use clap_complete_fig::Fig; use clap_complete_nushell::Nushell; diff --git a/rustfmt.toml b/rustfmt.toml index c4a8b584..8308ec60 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -5,6 +5,7 @@ fn_params_layout = "Compressed" use_field_init_shorthand = true tab_spaces = 4 max_width = 100 +style_edition = "2024" # Unstable options, disabled by default. # imports_granularity = "Crate" diff --git a/src/app/data/process.rs b/src/app/data/process.rs index aef12e76..b6488942 100644 --- a/src/app/data/process.rs +++ b/src/app/data/process.rs @@ -1,8 +1,9 @@ use std::{collections::BTreeMap, vec::Vec}; -use crate::collection::processes::{Pid, ProcessHarvest}; use hashbrown::HashMap; +use crate::collection::processes::{Pid, ProcessHarvest}; + #[derive(Clone, Debug, Default)] pub struct ProcessData { /// A PID to process data map. diff --git a/src/app/data/store.rs b/src/app/data/store.rs index 9ae406e7..ad8a2ee6 100644 --- a/src/app/data/store.rs +++ b/src/app/data/store.rs @@ -3,18 +3,17 @@ use std::{ vec::Vec, }; +use super::{ProcessData, TimeSeriesData}; #[cfg(feature = "battery")] use crate::collection::batteries; use crate::{ app::AppConfigFields, - collection::{cpu, disks, memory::MemData, network, Data}, + collection::{Data, cpu, disks, memory::MemData, network}, dec_bytes_per_second_string, utils::data_units::DataUnit, widgets::{DiskWidgetData, TempWidgetData}, }; -use super::{ProcessData, TimeSeriesData}; - /// A collection of data. This is where we dump data into. /// /// TODO: Maybe reduce visibility of internal data, make it only accessible through DataStore? @@ -186,7 +185,7 @@ impl StoredData { { if !device.name.starts_with('/') { Some(device.name.as_str()) // use the whole zfs - // dataset name + // dataset name } else { device.name.split('/').last() } diff --git a/src/app/layout_manager.rs b/src/app/layout_manager.rs index 6465b84e..87a9830e 100644 --- a/src/app/layout_manager.rs +++ b/src/app/layout_manager.rs @@ -663,21 +663,20 @@ impl BottomLayout { BottomLayout { total_row_height_ratio: 3, rows: vec![ - BottomRow::new(vec![BottomCol::new(vec![ - BottomColRow::new(vec![cpu]).canvas_handled() + BottomRow::new(vec![ + BottomCol::new(vec![BottomColRow::new(vec![cpu]).canvas_handled()]) + .canvas_handled(), ]) - .canvas_handled()]) .canvas_handled(), - BottomRow::new(vec![BottomCol::new(vec![BottomColRow::new(vec![ - mem, net, + BottomRow::new(vec![ + BottomCol::new(vec![BottomColRow::new(vec![mem, net]).canvas_handled()]) + .canvas_handled(), ]) - .canvas_handled()]) - .canvas_handled()]) .canvas_handled(), - BottomRow::new(vec![BottomCol::new(vec![ - BottomColRow::new(vec![table]).canvas_handled() + BottomRow::new(vec![ + BottomCol::new(vec![BottomColRow::new(vec![table]).canvas_handled()]) + .canvas_handled(), ]) - .canvas_handled()]) .canvas_handled(), BottomRow::new(table_widgets).canvas_handled(), ], diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs index c2e25d1b..84b95242 100644 --- a/src/app/process_killer.rs +++ b/src/app/process_killer.rs @@ -6,7 +6,7 @@ use anyhow::bail; use windows::Win32::{ Foundation::{CloseHandle, HANDLE}, System::Threading::{ - OpenProcess, TerminateProcess, PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, + OpenProcess, PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, TerminateProcess, }, }; @@ -68,9 +68,11 @@ pub fn kill_process_given_pid(pid: Pid, signal: usize) -> anyhow::Result<()> { let err_code = std::io::Error::last_os_error().raw_os_error(); let err = match err_code { Some(libc::ESRCH) => "the target process did not exist.", - Some(libc::EPERM) => "the calling process does not have the permissions to terminate the target process(es).", + Some(libc::EPERM) => { + "the calling process does not have the permissions to terminate the target process(es)." + } Some(libc::EINVAL) => "an invalid signal was specified.", - _ => "Unknown error occurred." + _ => "Unknown error occurred.", }; if let Some(err_code) = err_code { diff --git a/src/app/states.rs b/src/app/states.rs index 642f6d3e..0c55919e 100644 --- a/src/app/states.rs +++ b/src/app/states.rs @@ -9,8 +9,8 @@ use crate::{ app::layout_manager::BottomWidgetType, constants, widgets::{ - query::ProcessQuery, BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, - NetWidgetState, ProcWidgetState, TempWidgetState, + BatteryWidgetState, CpuWidgetState, DiskTableWidget, MemWidgetState, NetWidgetState, + ProcWidgetState, TempWidgetState, query::ProcessQuery, }, }; diff --git a/src/canvas.rs b/src/canvas.rs index d3997f04..c86703f1 100644 --- a/src/canvas.rs +++ b/src/canvas.rs @@ -5,17 +5,17 @@ mod widgets; use itertools::izip; use tui::{ + Frame, Terminal, backend::Backend, layout::{Constraint, Direction, Layout, Rect}, text::Span, widgets::Paragraph, - Frame, Terminal, }; use crate::{ app::{ - layout_manager::{BottomColRow, BottomLayout, BottomWidgetType, IntermediaryConstraint}, App, + layout_manager::{BottomColRow, BottomLayout, BottomWidgetType, IntermediaryConstraint}, }, constants::*, options::config::style::Styles, @@ -362,11 +362,7 @@ impl Painter { && actual_cpu_data_len.saturating_sub(1) % 4 != 0, ); - if c <= 1 { - 1 - } else { - c - } + if c <= 1 { 1 } else { c } }; let mut mem_rows = 1; diff --git a/src/canvas/components/data_table/draw.rs b/src/canvas/components/data_table/draw.rs index 617c7611..d97c3b80 100644 --- a/src/canvas/components/data_table/draw.rs +++ b/src/canvas/components/data_table/draw.rs @@ -5,10 +5,10 @@ use std::{ use concat_string::concat_string; use tui::{ + Frame, layout::{Constraint, Direction, Layout, Rect}, text::{Line, Span, Text}, widgets::{Block, Row, Table}, - Frame, }; use super::{ @@ -17,7 +17,7 @@ use super::{ }; use crate::{ app::layout_manager::BottomWidget, - canvas::{drawing_utils::widget_block, Painter}, + canvas::{Painter, drawing_utils::widget_block}, constants::TABLE_GAP_HEIGHT_LIMIT, utils::strings::truncate_to_text, }; diff --git a/src/canvas/components/time_graph.rs b/src/canvas/components/time_graph.rs index adb9123a..c6829bc3 100644 --- a/src/canvas/components/time_graph.rs +++ b/src/canvas/components/time_graph.rs @@ -1,16 +1,15 @@ mod time_chart; -pub use time_chart::*; - use std::{borrow::Cow, time::Instant}; use concat_string::concat_string; +pub use time_chart::*; use tui::{ + Frame, layout::{Constraint, Rect}, style::Style, symbols::Marker, text::{Line, Span}, widgets::{BorderType, GraphType}, - Frame, }; use crate::{app::data::Values, canvas::drawing_utils::widget_block}; diff --git a/src/canvas/components/time_graph/time_chart.rs b/src/canvas/components/time_graph/time_chart.rs index 2de80c0e..69af0e81 100644 --- a/src/canvas/components/time_graph/time_chart.rs +++ b/src/canvas/components/time_graph/time_chart.rs @@ -16,13 +16,13 @@ use tui::{ style::{Color, Style, Styled}, symbols::{self, Marker}, text::{Line, Span}, - widgets::{block::BlockExt, Block, Borders, GraphType, Widget}, + widgets::{Block, Borders, GraphType, Widget, block::BlockExt}, }; use unicode_width::UnicodeWidthStr; use crate::{ app::data::Values, - utils::general::{saturating_log10, saturating_log2}, + utils::general::{saturating_log2, saturating_log10}, }; pub const DEFAULT_LEGEND_CONSTRAINTS: (Constraint, Constraint) = @@ -1116,7 +1116,7 @@ mod tests { assert!(layout.legend_area.is_some()); assert_eq!(layout.legend_area.unwrap().height, 4); // 2 for borders, 2 - // for rows + // for rows } #[test] diff --git a/src/canvas/components/time_graph/time_chart/canvas.rs b/src/canvas/components/time_graph/time_chart/canvas.rs index c66b0e69..910aad0e 100644 --- a/src/canvas/components/time_graph/time_chart/canvas.rs +++ b/src/canvas/components/time_graph/time_chart/canvas.rs @@ -22,8 +22,8 @@ use tui::{ symbols, text::Line, widgets::{ - canvas::{Line as CanvasLine, Points}, Block, Widget, + canvas::{Line as CanvasLine, Points}, }, }; diff --git a/src/canvas/components/time_graph/time_chart/points.rs b/src/canvas/components/time_graph/time_chart/points.rs index 95ec8e85..55282cd6 100644 --- a/src/canvas/components/time_graph/time_chart/points.rs +++ b/src/canvas/components/time_graph/time_chart/points.rs @@ -2,8 +2,8 @@ use itertools::Itertools; use tui::{ style::Color, widgets::{ - canvas::{Line as CanvasLine, Points}, GraphType, + canvas::{Line as CanvasLine, Points}, }, }; diff --git a/src/canvas/components/widget_carousel.rs b/src/canvas/components/widget_carousel.rs index c1bdb12e..b5b07e50 100644 --- a/src/canvas/components/widget_carousel.rs +++ b/src/canvas/components/widget_carousel.rs @@ -1,12 +1,12 @@ use tui::{ + Frame, layout::{Alignment, Constraint, Direction, Layout, Rect}, text::{Line, Span}, widgets::{Block, Paragraph}, - Frame, }; use crate::{ - app::{layout_manager::BottomWidgetType, App}, + app::{App, layout_manager::BottomWidgetType}, canvas::Painter, }; diff --git a/src/canvas/dialogs/dd_dialog.rs b/src/canvas/dialogs/dd_dialog.rs index 1052a153..8cf8b3ca 100644 --- a/src/canvas/dialogs/dd_dialog.rs +++ b/src/canvas/dialogs/dd_dialog.rs @@ -2,15 +2,15 @@ use std::cmp::min; use tui::{ + Frame, layout::{Alignment, Constraint, Direction, Layout, Rect}, text::{Line, Span, Text}, widgets::{Block, Paragraph, Wrap}, - Frame, }; use crate::{ app::{App, KillSignal, MAX_PROCESS_SIGNAL}, - canvas::{drawing_utils::dialog_block, Painter}, + canvas::{Painter, drawing_utils::dialog_block}, widgets::ProcWidgetMode, }; diff --git a/src/canvas/dialogs/help_dialog.rs b/src/canvas/dialogs/help_dialog.rs index ea7ca315..6f2aad85 100644 --- a/src/canvas/dialogs/help_dialog.rs +++ b/src/canvas/dialogs/help_dialog.rs @@ -1,16 +1,16 @@ use std::cmp::{max, min}; use tui::{ + Frame, layout::{Alignment, Rect}, text::{Line, Span}, widgets::{Paragraph, Wrap}, - Frame, }; use unicode_width::UnicodeWidthStr; use crate::{ app::App, - canvas::{drawing_utils::dialog_block, Painter}, + canvas::{Painter, drawing_utils::dialog_block}, constants::{self, HELP_TEXT}, }; diff --git a/src/canvas/widgets/battery_display.rs b/src/canvas/widgets/battery_display.rs index 1754bfac..8cfa0f52 100644 --- a/src/canvas/widgets/battery_display.rs +++ b/src/canvas/widgets/battery_display.rs @@ -1,16 +1,16 @@ use std::cmp::min; use tui::{ + Frame, layout::{Constraint, Direction, Layout, Rect}, text::{Line, Span}, widgets::{Cell, Paragraph, Row, Table, Tabs}, - Frame, }; use unicode_width::UnicodeWidthStr; use crate::{ app::App, - canvas::{drawing_utils::widget_block, Painter}, + canvas::{Painter, drawing_utils::widget_block}, collection::batteries::BatteryState, constants::*, }; diff --git a/src/canvas/widgets/cpu_basic.rs b/src/canvas/widgets/cpu_basic.rs index b00df731..634e8105 100644 --- a/src/canvas/widgets/cpu_basic.rs +++ b/src/canvas/widgets/cpu_basic.rs @@ -2,16 +2,16 @@ use std::cmp::min; use itertools::{Either, Itertools}; use tui::{ - layout::{Constraint, Direction, Layout, Rect}, Frame, + layout::{Constraint, Direction, Layout, Rect}, }; use crate::{ app::App, canvas::{ + Painter, components::pipe_gauge::{LabelLimit, PipeGauge}, drawing_utils::widget_block, - Painter, }, collection::cpu::{CpuData, CpuDataType}, }; diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index 33c98441..e8933c61 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -1,20 +1,20 @@ use std::borrow::Cow; use tui::{ + Frame, layout::{Constraint, Direction, Layout, Rect}, symbols::Marker, - Frame, }; use crate::{ - app::{data::StoredData, layout_manager::WidgetDirection, App}, + app::{App, data::StoredData, layout_manager::WidgetDirection}, canvas::{ + Painter, components::{ data_table::{DrawInfo, SelectionState}, time_graph::{AxisBound, GraphData, TimeGraph}, }, drawing_utils::should_hide_x_label, - Painter, }, collection::cpu::CpuData, widgets::CpuWidgetState, @@ -158,10 +158,12 @@ impl Painter { [(offset_position - show_avg_offset) % self.styles.cpu_colour_styles.len()] }; - vec![GraphData::default() - .style(style) - .time(time) - .values(&cpu_points[current_scroll_position - 1])] + vec![ + GraphData::default() + .style(style) + .time(time) + .values(&cpu_points[current_scroll_position - 1]), + ] } else { vec![] } diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs index 0e7912a6..dbc16dfc 100644 --- a/src/canvas/widgets/disk_table.rs +++ b/src/canvas/widgets/disk_table.rs @@ -1,10 +1,10 @@ -use tui::{layout::Rect, Frame}; +use tui::{Frame, layout::Rect}; use crate::{ app, canvas::{ - components::data_table::{DrawInfo, SelectionState}, Painter, + components::data_table::{DrawInfo, SelectionState}, }, }; diff --git a/src/canvas/widgets/mem_basic.rs b/src/canvas/widgets/mem_basic.rs index e1b3d1ba..a2f66d44 100644 --- a/src/canvas/widgets/mem_basic.rs +++ b/src/canvas/widgets/mem_basic.rs @@ -1,13 +1,13 @@ use std::borrow::Cow; use tui::{ - layout::{Constraint, Direction, Layout, Rect}, Frame, + layout::{Constraint, Direction, Layout, Rect}, }; use crate::{ app::App, - canvas::{components::pipe_gauge::PipeGauge, drawing_utils::widget_block, Painter}, + canvas::{Painter, components::pipe_gauge::PipeGauge, drawing_utils::widget_block}, collection::memory::MemData, get_binary_unit_and_denominator, }; diff --git a/src/canvas/widgets/mem_graph.rs b/src/canvas/widgets/mem_graph.rs index d9069487..2f13e817 100644 --- a/src/canvas/widgets/mem_graph.rs +++ b/src/canvas/widgets/mem_graph.rs @@ -1,18 +1,18 @@ use std::{borrow::Cow, time::Instant}; use tui::{ + Frame, layout::{Constraint, Rect}, style::Style, symbols::Marker, - Frame, }; use crate::{ - app::{data::Values, App}, + app::{App, data::Values}, canvas::{ + Painter, components::time_graph::{AxisBound, GraphData, TimeGraph}, drawing_utils::should_hide_x_label, - Painter, }, collection::memory::MemData, get_binary_unit_and_denominator, diff --git a/src/canvas/widgets/network_basic.rs b/src/canvas/widgets/network_basic.rs index fd4c69dc..caf82903 100644 --- a/src/canvas/widgets/network_basic.rs +++ b/src/canvas/widgets/network_basic.rs @@ -1,13 +1,13 @@ use tui::{ + Frame, layout::{Constraint, Direction, Layout, Rect}, text::{Line, Span}, widgets::{Block, Paragraph}, - Frame, }; use crate::{ app::App, - canvas::{drawing_utils::widget_block, Painter}, + canvas::{Painter, drawing_utils::widget_block}, utils::data_units::{convert_bits, get_unit_prefix}, }; diff --git a/src/canvas/widgets/network_graph.rs b/src/canvas/widgets/network_graph.rs index b0f3638a..3e5f1dd8 100644 --- a/src/canvas/widgets/network_graph.rs +++ b/src/canvas/widgets/network_graph.rs @@ -1,23 +1,23 @@ use std::time::Duration; use tui::{ + Frame, layout::{Constraint, Direction, Layout, Rect}, symbols::Marker, text::Text, widgets::{Block, Borders, Row, Table}, - Frame, }; use crate::{ app::{App, AppConfigFields, AxisScaling}, canvas::{ + Painter, components::time_graph::{AxisBound, ChartScaling, GraphData, TimeGraph}, drawing_utils::should_hide_x_label, - Painter, }, utils::{ data_units::*, - general::{saturating_log10, saturating_log2}, + general::{saturating_log2, saturating_log10}, }, widgets::NetWidgetHeightCache, }; @@ -106,7 +106,7 @@ impl Painter { for (&time, &v) in rx_points .iter_along_base(time) .rev() - .take_while(|(&time, _)| time >= first_time) + .take_while(|&(&time, _)| time >= first_time) { if v > biggest { biggest = v; @@ -117,7 +117,7 @@ impl Painter { for (&time, &v) in tx_points .iter_along_base(time) .rev() - .take_while(|(&time, _)| time >= first_time) + .take_while(|&(&time, _)| time >= first_time) { if v > biggest { biggest = v; diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index c19d3875..22614508 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -1,18 +1,18 @@ use tui::{ + Frame, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::Style, text::{Line, Span}, widgets::Paragraph, - Frame, }; use unicode_segmentation::UnicodeSegmentation; use crate::{ app::{App, AppSearchState}, canvas::{ + Painter, components::data_table::{DrawInfo, SelectionState}, drawing_utils::widget_block, - Painter, }, }; diff --git a/src/canvas/widgets/temperature_table.rs b/src/canvas/widgets/temperature_table.rs index c5fff41b..96bda698 100644 --- a/src/canvas/widgets/temperature_table.rs +++ b/src/canvas/widgets/temperature_table.rs @@ -1,10 +1,10 @@ -use tui::{layout::Rect, Frame}; +use tui::{Frame, layout::Rect}; use crate::{ app, canvas::{ - components::data_table::{DrawInfo, SelectionState}, Painter, + components::data_table::{DrawInfo, SelectionState}, }, }; diff --git a/src/collection/amd.rs b/src/collection/amd.rs index 93eba843..26f10090 100644 --- a/src/collection/amd.rs +++ b/src/collection/amd.rs @@ -1,10 +1,5 @@ mod amdgpu_marketing; -use crate::{ - app::{filter::Filter, layout_manager::UsedWidgets}, - collection::{memory::MemData, temperature::TempSensorData}, -}; -use hashbrown::{HashMap, HashSet}; use std::{ fs::{self, read_to_string}, num::NonZeroU64, @@ -13,6 +8,13 @@ use std::{ time::{Duration, Instant}, }; +use hashbrown::{HashMap, HashSet}; + +use crate::{ + app::{filter::Filter, layout_manager::UsedWidgets}, + collection::{memory::MemData, temperature::TempSensorData}, +}; + // TODO: May be able to clean up some of these, Option for example is a bit redundant. pub struct AMDGPUData { pub memory: Option>, diff --git a/src/collection/batteries.rs b/src/collection/batteries.rs index 778d3320..6a0ce7dc 100644 --- a/src/collection/batteries.rs +++ b/src/collection/batteries.rs @@ -11,8 +11,8 @@ //! For more information, refer to the [starship_battery](https://github.com/starship/rust-battery) repo/docs. use starship_battery::{ - units::{power::watt, ratio::percent, time::second}, Battery, Manager, State, + units::{power::watt, ratio::percent, time::second}, }; /// Battery state. diff --git a/src/collection/disks/freebsd.rs b/src/collection/disks/freebsd.rs index fbc4295b..90f2c13d 100644 --- a/src/collection/disks/freebsd.rs +++ b/src/collection/disks/freebsd.rs @@ -5,8 +5,8 @@ use std::io; use hashbrown::HashMap; use serde::Deserialize; -use super::{keep_disk_entry, DiskHarvest, IoHarvest}; -use crate::collection::{deserialize_xo, disks::IoData, error::CollectionResult, DataCollector}; +use super::{DiskHarvest, IoHarvest, keep_disk_entry}; +use crate::collection::{DataCollector, deserialize_xo, disks::IoData, error::CollectionResult}; #[derive(Deserialize, Debug, Default)] #[serde(rename_all = "kebab-case")] diff --git a/src/collection/disks/other.rs b/src/collection/disks/other.rs index bd2d461a..627bf89f 100644 --- a/src/collection/disks/other.rs +++ b/src/collection/disks/other.rs @@ -1,6 +1,6 @@ //! Fallback disk info using sysinfo. -use super::{keep_disk_entry, DiskHarvest}; +use super::{DiskHarvest, keep_disk_entry}; use crate::collection::DataCollector; pub(crate) fn get_disk_usage(collector: &DataCollector) -> anyhow::Result> { diff --git a/src/collection/disks/unix.rs b/src/collection/disks/unix.rs index 63759e9f..1f4dbe9b 100644 --- a/src/collection/disks/unix.rs +++ b/src/collection/disks/unix.rs @@ -24,7 +24,7 @@ cfg_if::cfg_if! { use file_systems::*; use usage::*; -use super::{keep_disk_entry, DiskHarvest}; +use super::{DiskHarvest, keep_disk_entry}; use crate::collection::DataCollector; /// Returns the disk usage of the mounted (and for now, physical) disks. diff --git a/src/collection/disks/unix/macos/io_kit/bindings.rs b/src/collection/disks/unix/macos/io_kit/bindings.rs index 8e5180d5..ddf4bf7e 100644 --- a/src/collection/disks/unix/macos/io_kit/bindings.rs +++ b/src/collection/disks/unix/macos/io_kit/bindings.rs @@ -6,7 +6,7 @@ //! Ideally, we can remove this if sysinfo ever gains disk I/O capabilities. use core_foundation::{ - base::{mach_port_t, CFAllocatorRef}, + base::{CFAllocatorRef, mach_port_t}, dictionary::CFMutableDictionaryRef, }; use libc::c_char; @@ -32,8 +32,9 @@ pub const kIOServicePlane: &str = "IOService\0"; #[expect(non_upper_case_globals)] pub const kIOMediaClass: &str = "IOMedia\0"; -// See [here](https://developer.apple.com/documentation/iokit) for more details. -extern "C" { +// SAFETY: Bindings like this are inherently unsafe. See [here](https://developer.apple.com/documentation/iokit) for +// more details. +unsafe extern "C" { pub fn IOServiceGetMatchingServices( mainPort: mach_port_t, matching: CFMutableDictionaryRef, existing: *mut io_iterator_t, diff --git a/src/collection/disks/unix/macos/io_kit/io_disks.rs b/src/collection/disks/unix/macos/io_kit/io_disks.rs index 9552b0b7..0bb13ab6 100644 --- a/src/collection/disks/unix/macos/io_kit/io_disks.rs +++ b/src/collection/disks/unix/macos/io_kit/io_disks.rs @@ -1,7 +1,7 @@ use anyhow::bail; use mach2::kern_return; -use super::{bindings::*, IoIterator}; +use super::{IoIterator, bindings::*}; pub fn get_disks() -> anyhow::Result { let mut media_iter: io_iterator_t = 0; diff --git a/src/collection/disks/unix/macos/io_kit/io_object.rs b/src/collection/disks/unix/macos/io_kit/io_object.rs index f7aa43ab..0b64504e 100644 --- a/src/collection/disks/unix/macos/io_kit/io_object.rs +++ b/src/collection/disks/unix/macos/io_kit/io_object.rs @@ -5,7 +5,7 @@ use std::mem; use anyhow::{anyhow, bail}; use core_foundation::{ - base::{kCFAllocatorDefault, CFType, TCFType, ToVoid}, + base::{CFType, TCFType, ToVoid, kCFAllocatorDefault}, dictionary::{ CFDictionary, CFDictionaryGetTypeID, CFDictionaryRef, CFMutableDictionary, CFMutableDictionaryRef, diff --git a/src/collection/disks/unix/other/bindings.rs b/src/collection/disks/unix/other/bindings.rs index 3c5739cc..3b81c193 100644 --- a/src/collection/disks/unix/other/bindings.rs +++ b/src/collection/disks/unix/other/bindings.rs @@ -5,9 +5,10 @@ use std::io::Error; const MNT_NOWAIT: libc::c_int = 2; -extern "C" { +// SAFETY: Bindings like this are inherently unsafe. +unsafe extern "C" { fn getfsstat64(buf: *mut libc::statfs, bufsize: libc::c_int, flags: libc::c_int) - -> libc::c_int; + -> libc::c_int; } /// Returns all the mounts on the system at the moment. diff --git a/src/collection/disks/unix/other/partition.rs b/src/collection/disks/unix/other/partition.rs index e5888bf7..d3461e80 100644 --- a/src/collection/disks/unix/other/partition.rs +++ b/src/collection/disks/unix/other/partition.rs @@ -57,7 +57,7 @@ fn partitions_iter() -> anyhow::Result> { let mounts = bindings::mounts()?; unsafe fn ptr_to_cow<'a>(ptr: *const i8) -> std::borrow::Cow<'a, str> { - CStr::from_ptr(ptr).to_string_lossy() + unsafe { CStr::from_ptr(ptr).to_string_lossy() } } Ok(mounts.into_iter().map(|stat| { diff --git a/src/collection/disks/windows.rs b/src/collection/disks/windows.rs index 39af6203..a32e94a2 100644 --- a/src/collection/disks/windows.rs +++ b/src/collection/disks/windows.rs @@ -5,8 +5,8 @@ mod bindings; use bindings::*; use itertools::Itertools; -use super::{keep_disk_entry, DiskHarvest}; -use crate::collection::{disks::IoCounters, DataCollector}; +use super::{DiskHarvest, keep_disk_entry}; +use crate::collection::{DataCollector, disks::IoCounters}; /// Returns I/O stats. pub(crate) fn io_stats() -> anyhow::Result> { diff --git a/src/collection/disks/windows/bindings.rs b/src/collection/disks/windows/bindings.rs index 9c7b2390..0c997d1c 100644 --- a/src/collection/disks/windows/bindings.rs +++ b/src/collection/disks/windows/bindings.rs @@ -11,13 +11,13 @@ use anyhow::bail; use windows::Win32::{ Foundation::{self, CloseHandle, HANDLE}, Storage::FileSystem::{ - CreateFileW, FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, - GetVolumeNameForVolumeMountPointW, FILE_FLAGS_AND_ATTRIBUTES, FILE_SHARE_READ, - FILE_SHARE_WRITE, OPEN_EXISTING, + CreateFileW, FILE_FLAGS_AND_ATTRIBUTES, FILE_SHARE_READ, FILE_SHARE_WRITE, + FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, GetVolumeNameForVolumeMountPointW, + OPEN_EXISTING, }, System::{ - Ioctl::{DISK_PERFORMANCE, IOCTL_DISK_PERFORMANCE}, IO::DeviceIoControl, + Ioctl::{DISK_PERFORMANCE, IOCTL_DISK_PERFORMANCE}, }, }; diff --git a/src/collection/disks/zfs_io_counters.rs b/src/collection/disks/zfs_io_counters.rs index 50e71218..20c4adba 100644 --- a/src/collection/disks/zfs_io_counters.rs +++ b/src/collection/disks/zfs_io_counters.rs @@ -65,11 +65,7 @@ pub fn zfs_io_stats() -> anyhow::Result> { .filter_map(|e| { e.ok().and_then(|d| { let p = d.path(); - if p.is_dir() { - Some(p) - } else { - None - } + if p.is_dir() { Some(p) } else { None } }) }) .collect(); diff --git a/src/collection/nvidia.rs b/src/collection/nvidia.rs index 7031a38c..56d04e1e 100644 --- a/src/collection/nvidia.rs +++ b/src/collection/nvidia.rs @@ -2,7 +2,7 @@ use std::{num::NonZeroU64, sync::OnceLock}; use hashbrown::HashMap; use nvml_wrapper::{ - enum_wrappers::device::TemperatureSensor, enums::device::UsedGpuMemory, error::NvmlError, Nvml, + Nvml, enum_wrappers::device::TemperatureSensor, enums::device::UsedGpuMemory, error::NvmlError, }; use crate::{ diff --git a/src/collection/processes.rs b/src/collection/processes.rs index 4452f142..a4250cee 100644 --- a/src/collection/processes.rs +++ b/src/collection/processes.rs @@ -34,7 +34,7 @@ cfg_if! { use std::{borrow::Cow, time::Duration}; -use super::{error::CollectionResult, DataCollector}; +use super::{DataCollector, error::CollectionResult}; cfg_if! { if #[cfg(target_family = "windows")] { diff --git a/src/collection/processes/freebsd.rs b/src/collection/processes/freebsd.rs index 31ca8aad..87dbaea4 100644 --- a/src/collection/processes/freebsd.rs +++ b/src/collection/processes/freebsd.rs @@ -5,7 +5,7 @@ use std::{io, process::Command}; use hashbrown::HashMap; use serde::{Deserialize, Deserializer}; -use crate::collection::{deserialize_xo, processes::UnixProcessExt, Pid}; +use crate::collection::{Pid, deserialize_xo, processes::UnixProcessExt}; #[derive(Deserialize, Debug, Default)] #[serde(rename_all = "kebab-case")] diff --git a/src/collection/processes/linux/mod.rs b/src/collection/processes/linux/mod.rs index 7ca1d73f..f4e41cb9 100644 --- a/src/collection/processes/linux/mod.rs +++ b/src/collection/processes/linux/mod.rs @@ -13,8 +13,8 @@ use hashbrown::HashSet; use process::*; use sysinfo::ProcessStatus; -use super::{process_status_str, Pid, ProcessHarvest, UserTable}; -use crate::collection::{error::CollectionResult, DataCollector}; +use super::{Pid, ProcessHarvest, UserTable, process_status_str}; +use crate::collection::{DataCollector, error::CollectionResult}; /// Maximum character length of a `/proc//stat`` process name. /// If it's equal or greater, then we instead refer to the command for the name. diff --git a/src/collection/processes/macos/sysctl_bindings.rs b/src/collection/processes/macos/sysctl_bindings.rs index 81948ec8..fce86e4b 100644 --- a/src/collection/processes/macos/sysctl_bindings.rs +++ b/src/collection/processes/macos/sysctl_bindings.rs @@ -3,10 +3,10 @@ use std::mem; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use libc::{ - boolean_t, c_char, c_long, c_short, c_uchar, c_ushort, c_void, dev_t, gid_t, itimerval, pid_t, - rusage, sigset_t, timeval, uid_t, xucred, CTL_KERN, KERN_PROC, KERN_PROC_PID, MAXCOMLEN, + CTL_KERN, KERN_PROC, KERN_PROC_PID, MAXCOMLEN, boolean_t, c_char, c_long, c_short, c_uchar, + c_ushort, c_void, dev_t, gid_t, itimerval, pid_t, rusage, sigset_t, timeval, uid_t, xucred, }; use mach2::vm_types::user_addr_t; diff --git a/src/collection/processes/unix/process_ext.rs b/src/collection/processes/unix/process_ext.rs index f322ed84..7bae162a 100644 --- a/src/collection/processes/unix/process_ext.rs +++ b/src/collection/processes/unix/process_ext.rs @@ -5,8 +5,8 @@ use std::{io, time::Duration}; use hashbrown::HashMap; use sysinfo::{ProcessStatus, System}; -use super::{process_status_str, ProcessHarvest}; -use crate::collection::{error::CollectionResult, processes::UserTable, Pid}; +use super::{ProcessHarvest, process_status_str}; +use crate::collection::{Pid, error::CollectionResult, processes::UserTable}; pub(crate) trait UnixProcessExt { fn sysinfo_process_data( diff --git a/src/collection/processes/windows.rs b/src/collection/processes/windows.rs index da0d42d6..8814fcdd 100644 --- a/src/collection/processes/windows.rs +++ b/src/collection/processes/windows.rs @@ -2,8 +2,8 @@ use std::time::Duration; -use super::{process_status_str, ProcessHarvest}; -use crate::collection::{error::CollectionResult, DataCollector}; +use super::{ProcessHarvest, process_status_str}; +use crate::collection::{DataCollector, error::CollectionResult}; // TODO: There's a lot of shared code with this and the unix impl. pub fn sysinfo_process_data( diff --git a/src/event.rs b/src/event.rs index b3c2d7d0..75e20da7 100644 --- a/src/event.rs +++ b/src/event.rs @@ -5,7 +5,7 @@ use std::sync::mpsc::Sender; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind}; use crate::{ - app::{layout_manager::WidgetDirection, App}, + app::{App, layout_manager::WidgetDirection}, collection::Data, }; diff --git a/src/lib.rs b/src/lib.rs index 5b778a1b..659dcb97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,34 +25,32 @@ pub mod widgets; use std::{ boxed::Box, - io::{stderr, stdout, Write}, + io::{Write, stderr, stdout}, panic::{self, PanicHookInfo}, sync::{ - mpsc::{self, Receiver, Sender}, Arc, + mpsc::{self, Receiver, Sender}, }, thread::{self, JoinHandle}, time::{Duration, Instant}, }; -use app::{layout_manager::UsedWidgets, App, AppConfigFields, DataFilters}; +use app::{App, AppConfigFields, DataFilters, layout_manager::UsedWidgets}; use crossterm::{ cursor::{Hide, Show}, event::{ - poll, read, DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, - EnableMouseCapture, Event, KeyEventKind, MouseEventKind, + DisableBracketedPaste, DisableMouseCapture, EnableBracketedPaste, EnableMouseCapture, + Event, KeyEventKind, MouseEventKind, poll, read, }, execute, - terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, + terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode}, }; -use event::{handle_key_event_or_break, handle_mouse_event, BottomEvent, CollectionThreadEvent}; +use event::{BottomEvent, CollectionThreadEvent, handle_key_event_or_break, handle_mouse_event}; use options::{args, get_or_create_config, init_app}; -use tui::{backend::CrosstermBackend, Terminal}; -use utils::cancellation_token::CancellationToken; -use utils::conversion::*; - +use tui::{Terminal, backend::CrosstermBackend}; #[allow(unused_imports, reason = "this is needed if logging is enabled")] use utils::logging::*; +use utils::{cancellation_token::CancellationToken, conversion::*}; // Used for heap allocation debugging purposes. // #[global_allocator] @@ -323,13 +321,15 @@ pub fn start_bottom(enable_error_hook: &mut bool) -> anyhow::Result<()> { let cancellation_token = cancellation_token.clone(); let cleaning_sender = sender.clone(); let offset_wait = Duration::from_millis(app.app_config_fields.retention_ms + 60000); - thread::spawn(move || loop { - if cancellation_token.sleep_with_cancellation(offset_wait) { - break; - } + thread::spawn(move || { + loop { + if cancellation_token.sleep_with_cancellation(offset_wait) { + break; + } - if cleaning_sender.send(BottomEvent::Clean).is_err() { - break; + if cleaning_sender.send(BottomEvent::Clean).is_err() { + break; + } } }) }; diff --git a/src/options.rs b/src/options.rs index 92e7473f..10946346 100644 --- a/src/options.rs +++ b/src/options.rs @@ -16,8 +16,8 @@ use std::{ }; use anyhow::{Context, Result}; -use config::style::Styles; pub use config::Config; +use config::style::Styles; use data::TemperatureType; pub(crate) use error::{OptionError, OptionResult}; use hashbrown::{HashMap, HashSet}; @@ -28,7 +28,7 @@ use starship_battery::Manager; use self::{ args::BottomArgs, - config::{layout::Row, IgnoreList, StringOrNum}, + config::{IgnoreList, StringOrNum, layout::Row}, }; use crate::{ app::{filter::Filter, layout_manager::*, *}, @@ -1009,7 +1009,7 @@ fn get_memory_legend_position( mod test { use clap::Parser; - use super::{get_time_interval, Config}; + use super::{Config, get_time_interval}; use crate::{ app::App, args::BottomArgs, @@ -1234,10 +1234,10 @@ mod test { fn test_get_config_path_macos() { use std::path::PathBuf; - use super::{get_config_path, DEFAULT_CONFIG_FILE_LOCATION}; + use super::{DEFAULT_CONFIG_FILE_LOCATION, get_config_path}; // Case three: no previous config, no XDG var. - // SAFETY: this is the only test that does this + // SAFETY: This is fine, this is just a test, and no other test affects env vars. unsafe { std::env::remove_var("XDG_CONFIG_HOME"); } @@ -1255,7 +1255,10 @@ mod test { } // Case two: no previous config, XDG var exists. - std::env::set_var("XDG_CONFIG_HOME", "/tmp"); + // SAFETY: This is fine, this is just a test, and no other test affects env vars. + unsafe { + std::env::set_var("XDG_CONFIG_HOME", "/tmp"); + } let mut case_2 = PathBuf::new(); case_2.push("/tmp"); case_2.push(DEFAULT_CONFIG_FILE_LOCATION); diff --git a/src/options/config/style.rs b/src/options/config/style.rs index 5374604d..96d8cdf4 100644 --- a/src/options/config/style.rs +++ b/src/options/config/style.rs @@ -25,7 +25,7 @@ use utils::{opt, set_colour, set_colour_list, set_style}; use widgets::WidgetStyle; use super::Config; -use crate::options::{args::BottomArgs, OptionError, OptionResult}; +use crate::options::{OptionError, OptionResult, args::BottomArgs}; #[derive(Clone, Debug, Deserialize, Serialize)] #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))] diff --git a/src/options/config/style/themes/gruvbox.rs b/src/options/config/style/themes/gruvbox.rs index d6054820..0cbf1f88 100644 --- a/src/options/config/style/themes/gruvbox.rs +++ b/src/options/config/style/themes/gruvbox.rs @@ -4,7 +4,7 @@ use tui::{ }; use super::{color, hex}; -use crate::options::config::style::{utils::convert_hex_to_color, Styles}; +use crate::options::config::style::{Styles, utils::convert_hex_to_color}; impl Styles { pub(crate) fn gruvbox_palette() -> Self { diff --git a/src/options/config/style/themes/nord.rs b/src/options/config/style/themes/nord.rs index f55dcca9..28fa7be1 100644 --- a/src/options/config/style/themes/nord.rs +++ b/src/options/config/style/themes/nord.rs @@ -4,7 +4,7 @@ use tui::{ }; use super::{color, hex}; -use crate::options::config::style::{utils::convert_hex_to_color, Styles}; +use crate::options::config::style::{Styles, utils::convert_hex_to_color}; impl Styles { pub(crate) fn nord_palette() -> Self { diff --git a/src/options/config/style/utils.rs b/src/options/config/style/utils.rs index f589e7a6..8d146837 100644 --- a/src/options/config/style/utils.rs +++ b/src/options/config/style/utils.rs @@ -135,8 +135,8 @@ macro_rules! set_style { match &style { TextStyleConfig::Colour(colour) => { $palette_field = $palette_field.fg( - crate::options::config::style::utils::str_to_colour(&colour.0) - .map_err(|err| match stringify!($config_location).split_once(".") { + crate::options::config::style::utils::str_to_colour(&colour.0).map_err( + |err| match stringify!($config_location).split_once(".") { Some((_, loc)) => crate::options::OptionError::config(format!( "Please update 'styles.{loc}.{}' in your config file. {err}", stringify!($field) @@ -145,55 +145,71 @@ macro_rules! set_style { "Please update 'styles.{}' in your config file. {err}", stringify!($field) )), - })? + }, + )?, ); } - TextStyleConfig::TextStyle {color, bg_color, bold, italics} => { + TextStyleConfig::TextStyle { + color, + bg_color, + bold, + italics, + } => { if let Some(fg) = &color { - $palette_field = $palette_field.fg( - crate::options::config::style::utils::str_to_colour(&fg.0) - .map_err(|err| match stringify!($config_location).split_once(".") { - Some((_, loc)) => crate::options::OptionError::config(format!( - "Please update 'styles.{loc}.{}' in your config file. {err}", - stringify!($field) - )), - None => crate::options::OptionError::config(format!( - "Please update 'styles.{}' in your config file. {err}", - stringify!($field) - )), - })? - ); + $palette_field = $palette_field + .fg(crate::options::config::style::utils::str_to_colour( + &fg.0, + ) + .map_err(|err| { + match stringify!($config_location).split_once(".") { + Some((_, loc)) => crate::options::OptionError::config(format!( + "Please update 'styles.{loc}.{}' in your config file. {err}", + stringify!($field) + )), + None => crate::options::OptionError::config(format!( + "Please update 'styles.{}' in your config file. {err}", + stringify!($field) + )), + } + })?); } if let Some(bg) = &bg_color { - $palette_field = $palette_field.bg( - crate::options::config::style::utils::str_to_colour(&bg.0) - .map_err(|err| match stringify!($config_location).split_once(".") { - Some((_, loc)) => crate::options::OptionError::config(format!( - "Please update 'styles.{loc}.{}' in your config file. {err}", - stringify!($field) - )), - None => crate::options::OptionError::config(format!( - "Please update 'styles.{}' in your config file. {err}", - stringify!($field) - )), - })? - ); + $palette_field = $palette_field + .bg(crate::options::config::style::utils::str_to_colour( + &bg.0, + ) + .map_err(|err| { + match stringify!($config_location).split_once(".") { + Some((_, loc)) => crate::options::OptionError::config(format!( + "Please update 'styles.{loc}.{}' in your config file. {err}", + stringify!($field) + )), + None => crate::options::OptionError::config(format!( + "Please update 'styles.{}' in your config file. {err}", + stringify!($field) + )), + } + })?); } if let Some(bold) = &bold { if *bold { - $palette_field = $palette_field.add_modifier(tui::style::Modifier::BOLD); + $palette_field = + $palette_field.add_modifier(tui::style::Modifier::BOLD); } else { - $palette_field = $palette_field.remove_modifier(tui::style::Modifier::BOLD); + $palette_field = + $palette_field.remove_modifier(tui::style::Modifier::BOLD); } } if let Some(italics) = &italics { if *italics { - $palette_field = $palette_field.add_modifier(tui::style::Modifier::ITALIC); + $palette_field = + $palette_field.add_modifier(tui::style::Modifier::ITALIC); } else { - $palette_field = $palette_field.remove_modifier(tui::style::Modifier::ITALIC); + $palette_field = + $palette_field.remove_modifier(tui::style::Modifier::ITALIC); } } } diff --git a/src/options/config/style/widgets.rs b/src/options/config/style/widgets.rs index 68f04d96..012837ea 100644 --- a/src/options/config/style/widgets.rs +++ b/src/options/config/style/widgets.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use super::{borders::WidgetBorderType, ColorStr, TextStyleConfig}; +use super::{ColorStr, TextStyleConfig, borders::WidgetBorderType}; /// General styling for generic widgets. #[derive(Clone, Debug, Default, Deserialize, Serialize)] diff --git a/src/utils/general.rs b/src/utils/general.rs index 6b634e31..351329b5 100644 --- a/src/utils/general.rs +++ b/src/utils/general.rs @@ -64,20 +64,12 @@ clamp_num_impl!(u8, u16, u32, u64, usize); /// Checked log2. pub fn saturating_log2(value: f64) -> f64 { - if value > 0.0 { - value.log2() - } else { - 0.0 - } + if value > 0.0 { value.log2() } else { 0.0 } } /// Checked log10. pub fn saturating_log10(value: f64) -> f64 { - if value > 0.0 { - value.log10() - } else { - 0.0 - } + if value > 0.0 { value.log10() } else { 0.0 } } #[cfg(test)] diff --git a/src/widgets/cpu_graph.rs b/src/widgets/cpu_graph.rs index a0fc8edb..737c09bf 100644 --- a/src/widgets/cpu_graph.rs +++ b/src/widgets/cpu_graph.rs @@ -6,11 +6,11 @@ use tui::widgets::Row; use crate::{ app::AppConfigFields, canvas::{ + Painter, components::data_table::{ Column, ColumnHeader, DataTable, DataTableColumn, DataTableProps, DataTableStyling, DataToCell, }, - Painter, }, collection::cpu::{CpuData, CpuDataType}, options::config::{cpu::CpuDefault, style::Styles}, diff --git a/src/widgets/disk_table.rs b/src/widgets/disk_table.rs index 7561c150..9d71c9cc 100644 --- a/src/widgets/disk_table.rs +++ b/src/widgets/disk_table.rs @@ -3,7 +3,7 @@ use std::{borrow::Cow, cmp::max, num::NonZeroU16}; use serde::Deserialize; use crate::{ - app::{data::StoredData, AppConfigFields}, + app::{AppConfigFields, data::StoredData}, canvas::components::data_table::{ ColumnHeader, DataTableColumn, DataTableProps, DataTableStyling, DataToCell, SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow, diff --git a/src/widgets/process_table.rs b/src/widgets/process_table.rs index 0c9c256b..00e18da7 100644 --- a/src/widgets/process_table.rs +++ b/src/widgets/process_table.rs @@ -10,13 +10,13 @@ use indexmap::IndexSet; use itertools::Itertools; pub use process_columns::*; pub use process_data::*; -use query::{parse_query, ProcessQuery}; +use query::{ProcessQuery, parse_query}; use sort_table::SortTableColumn; use crate::{ app::{ - data::{ProcessData, StoredData}, AppConfigFields, AppSearchState, + data::{ProcessData, StoredData}, }, canvas::components::data_table::{ Column, ColumnHeader, ColumnWidthBounds, DataTable, DataTableColumn, DataTableProps, diff --git a/src/widgets/process_table/process_data.rs b/src/widgets/process_table/process_data.rs index 7c1b216b..bc1373cc 100644 --- a/src/widgets/process_table/process_data.rs +++ b/src/widgets/process_table/process_data.rs @@ -1,6 +1,6 @@ use std::{ borrow::Cow, - cmp::{max, Ordering}, + cmp::{Ordering, max}, fmt::Display, num::NonZeroU16, time::Duration, @@ -12,12 +12,12 @@ use tui::widgets::Row; use super::process_columns::ProcColumn; use crate::{ canvas::{ - components::data_table::{DataTableColumn, DataToCell}, Painter, + components::data_table::{DataTableColumn, DataToCell}, }, collection::processes::{Pid, ProcessHarvest}, dec_bytes_per_second_string, - utils::data_units::{get_binary_bytes, get_decimal_bytes, GIBI_LIMIT, GIGA_LIMIT}, + utils::data_units::{GIBI_LIMIT, GIGA_LIMIT, get_binary_bytes, get_decimal_bytes}, }; #[derive(Clone, Debug)] @@ -391,9 +391,8 @@ impl DataToCell for ProcWidgetData { mod test { use std::time::Duration; - use crate::utils::data_units::*; - use super::*; + use crate::utils::data_units::*; #[test] fn test_format_time() { diff --git a/src/widgets/process_table/query.rs b/src/widgets/process_table/query.rs index eef8fba2..f15df56f 100644 --- a/src/widgets/process_table/query.rs +++ b/src/widgets/process_table/query.rs @@ -329,7 +329,7 @@ pub(crate) fn parse_query( or: None, regex_prefix: Some((prefix_type, StringQuery::Value(content))), compare_prefix: None, - }) + }); } PrefixType::Pid | PrefixType::State | PrefixType::User => { // We have to check if someone put an "="... diff --git a/src/widgets/temperature_table.rs b/src/widgets/temperature_table.rs index d9a8e4a7..65ee6b91 100644 --- a/src/widgets/temperature_table.rs +++ b/src/widgets/temperature_table.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, cmp::max, num::NonZeroU16}; use crate::{ - app::{data::TypedTemperature, AppConfigFields}, + app::{AppConfigFields, data::TypedTemperature}, canvas::components::data_table::{ ColumnHeader, DataTableColumn, DataTableProps, DataTableStyling, DataToCell, SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow, diff --git a/tests/integration/util.rs b/tests/integration/util.rs index e9e33652..f016ac4b 100644 --- a/tests/integration/util.rs +++ b/tests/integration/util.rs @@ -2,7 +2,7 @@ use std::{env, ffi::OsString, path::Path, process::Command}; use hashbrown::HashMap; #[cfg(all(target_arch = "x86_64", target_os = "linux"))] -use portable_pty::{native_pty_system, Child, CommandBuilder, MasterPty, PtySize}; +use portable_pty::{Child, CommandBuilder, MasterPty, PtySize, native_pty_system}; pub fn abs_path(path: &str) -> OsString { let path = Path::new(path);