Skip to content

Commit

Permalink
refactor: somewhat migrate to Rust 2024 edition (#1681)
Browse files Browse the repository at this point in the history
* refactor: try bumping to rust 2024 edition

* now run nightly fmt

* fix some macos changes

* only apply a few of these settings
  • Loading branch information
ClementTsang authored Feb 22, 2025
1 parent 9999a48 commit f7d070f
Show file tree
Hide file tree
Showing 62 changed files with 207 additions and 198 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/app/data/process.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
7 changes: 3 additions & 4 deletions src/app/data/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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()
}
Expand Down
19 changes: 9 additions & 10 deletions src/app/layout_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
Expand Down
8 changes: 5 additions & 3 deletions src/app/process_killer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/app/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down
10 changes: 3 additions & 7 deletions src/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/components/data_table/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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,
};
Expand Down
5 changes: 2 additions & 3 deletions src/canvas/components/time_graph.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
6 changes: 3 additions & 3 deletions src/canvas/components/time_graph/time_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/components/time_graph/time_chart/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use tui::{
symbols,
text::Line,
widgets::{
canvas::{Line as CanvasLine, Points},
Block, Widget,
canvas::{Line as CanvasLine, Points},
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/canvas/components/time_graph/time_chart/points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use itertools::Itertools;
use tui::{
style::Color,
widgets::{
canvas::{Line as CanvasLine, Points},
GraphType,
canvas::{Line as CanvasLine, Points},
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/canvas/components/widget_carousel.rs
Original file line number Diff line number Diff line change
@@ -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,
};

Expand Down
4 changes: 2 additions & 2 deletions src/canvas/dialogs/dd_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
4 changes: 2 additions & 2 deletions src/canvas/dialogs/help_dialog.rs
Original file line number Diff line number Diff line change
@@ -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},
};

Expand Down
4 changes: 2 additions & 2 deletions src/canvas/widgets/battery_display.rs
Original file line number Diff line number Diff line change
@@ -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::*,
};
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/widgets/cpu_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
16 changes: 9 additions & 7 deletions src/canvas/widgets/cpu_graph.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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![]
}
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/widgets/disk_table.rs
Original file line number Diff line number Diff line change
@@ -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},
},
};

Expand Down
Loading

0 comments on commit f7d070f

Please sign in to comment.