diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs index e81ee5a..4d91c22 100644 --- a/src/app_data/container_state.rs +++ b/src/app_data/container_state.rs @@ -68,15 +68,11 @@ impl StatefulList { String::from("") } else { let len = self.items.len(); - let c = if let Some(value) = self.state.selected() { - if len > 0 { + let c = self.state.selected().map_or(0, |value| if len > 0 { value + 1 } else { value - } - } else { - 0 - }; + }); format!("{}/{}", c, self.items.len()) } } @@ -95,7 +91,7 @@ pub enum State { } impl State { - pub fn get_color(&self) -> Color { + pub const fn get_color(&self) -> Color { match self { Self::Running => Color::Green, Self::Removing => Color::LightRed, @@ -105,7 +101,7 @@ impl State { } } // Dirty way to create order for the state, rather than impl Ord - pub fn order(&self) -> &'static str { + pub const fn order(&self) -> &'static str { match self { Self::Running => "a", Self::Paused => "b", @@ -158,7 +154,7 @@ pub enum DockerControls { } impl DockerControls { - pub fn get_color(&self) -> Color { + pub const fn get_color(&self) -> Color { match self { Self::Start => Color::Green, Self::Stop => Color::Red, @@ -205,7 +201,7 @@ pub struct CpuStats { } impl CpuStats { - pub fn new(value: f64) -> Self { + pub const fn new(value: f64) -> Self { Self { value } } } @@ -276,7 +272,7 @@ impl Ord for ByteStats { } impl ByteStats { - pub fn new(value: u64) -> Self { + pub const fn new(value: u64) -> Self { Self { value } } pub fn update(&mut self, value: u64) { @@ -423,8 +419,8 @@ pub struct Columns { } impl Columns { - // (Column titles, minimum header string length) - pub fn new() -> Self { + /// (Column titles, minimum header string length) + pub const fn new() -> Self { Self { state: (Header::State, 11), status: (Header::Status, 16), diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 678ce41..d725393 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -259,11 +259,7 @@ impl AppData { /// Get the title for log panel for selected container /// will be "logs x/x" pub fn get_log_title(&self) -> String { - if let Some(index) = self.get_selected_log_index() { - self.containers.items[index].logs.get_state_title() - } else { - String::from("") - } + self.get_selected_log_index().map_or_else(|| String::from(""), |index| self.containers.items[index].logs.get_state_title()) } /// select next selected log line diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 2aeb49d..0fc4a72 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -102,11 +102,7 @@ impl DockerData { let mem_stat = stats.memory_stats.usage.unwrap_or(0); let mem_limit = stats.memory_stats.limit.unwrap_or(0); - let some_key = if let Some(networks) = &stats.networks { - networks.keys().next().cloned() - } else { - None - }; + let some_key = stats.networks.as_ref().and_then(|networks| networks.keys().next().cloned()); let cpu_stats = Self::calculate_usage(&stats); diff --git a/src/main.rs b/src/main.rs index fec5651..12a74b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ #![forbid(unsafe_code)] #![warn(clippy::unused_async, clippy::unwrap_used, clippy::expect_used)] // Wanring - These are indeed pedantic -#![warn(clippy::pedantic)] -// #![warn(clippy::nursery)] +// #![warn(clippy::pedantic)] +#![warn(clippy::nursery)] #![allow(clippy::module_name_repetitions, clippy::doc_markdown)] // Only allow when debugging diff --git a/src/parse_args/mod.rs b/src/parse_args/mod.rs index d76f88a..a115aed 100644 --- a/src/parse_args/mod.rs +++ b/src/parse_args/mod.rs @@ -31,7 +31,7 @@ pub struct CliArgs { impl CliArgs { /// Parse cli arguments pub fn new() -> Self { - let args = CliArgs::parse(); + let args = Self::parse(); // Quit the program if the docker update argument is 0 // Should maybe change it to check if less than 100 diff --git a/src/ui/color_match.rs b/src/ui/color_match.rs index 5bf4ce1..149d74a 100644 --- a/src/ui/color_match.rs +++ b/src/ui/color_match.rs @@ -54,7 +54,7 @@ pub mod log_sanitizer { } /// Change from ansi to tui colors - fn color_ansi_to_tui(color: CansiColor) -> Color { + const fn color_ansi_to_tui(color: CansiColor) -> Color { match color { CansiColor::Black | CansiColor::BrightBlack => Color::Black, CansiColor::Red => Color::Red, diff --git a/src/ui/gui_state.rs b/src/ui/gui_state.rs index 0eec348..5711148 100644 --- a/src/ui/gui_state.rs +++ b/src/ui/gui_state.rs @@ -30,7 +30,7 @@ pub enum BoxLocation { } impl BoxLocation { - pub fn get_indexes(self) -> (usize, usize) { + pub const fn get_indexes(self) -> (usize, usize) { match self { Self::TopLeft => (0, 0), Self::TopCentre => (0, 1), @@ -45,7 +45,7 @@ impl BoxLocation { } // Should combine and just return a tuple? - pub fn get_horizontal_constraints( + pub const fn get_horizontal_constraints( self, blank_vertical: u16, text_width: u16, @@ -68,7 +68,7 @@ impl BoxLocation { ], } } - pub fn get_vertical_constraints( + pub const fn get_vertical_constraints( self, blank_vertical: u16, number_lines: u16, @@ -108,7 +108,7 @@ pub enum Loading { } impl Loading { - pub fn next(&self) -> Self { + pub const fn next(&self) -> Self { match self { Self::One => Self::Two, Self::Two => Self::Three, @@ -143,21 +143,21 @@ impl fmt::Display for Loading { } impl SelectablePanel { - pub fn title(self) -> &'static str { + pub const fn title(self) -> &'static str { match self { Self::Containers => "Containers", Self::Logs => "Logs", Self::Commands => "", } } - pub fn next(self) -> Self { + pub const fn next(self) -> Self { match self { Self::Containers => Self::Commands, Self::Commands => Self::Logs, Self::Logs => Self::Containers, } } - pub fn prev(self) -> Self { + pub const fn prev(self) -> Self { match self { Self::Containers => Self::Logs, Self::Commands => Self::Containers, diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 7d16f7f..55e3d50 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -72,7 +72,7 @@ pub async fn create_ui( } /// Run a loop to draw the gui -async fn run_app( +async fn run_app( terminal: &mut Terminal, app_data: Arc>, sender: Sender,