Skip to content

Commit

Permalink
refactor: map_or_else to map_or
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed Oct 7, 2022
1 parent 3e26f29 commit 5660b34
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/app_data/container_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ pub enum State {
impl State {
pub const fn get_color(self) -> Color {
match self {
Self::Running => Color::Green,
Self::Paused => Color::Yellow,
Self::Removing => Color::LightRed,
Self::Restarting => Color::LightGreen,
Self::Paused => Color::Yellow,
Self::Running => Color::Green,
_ => Color::Red,
}
}
Expand Down Expand Up @@ -204,19 +204,19 @@ impl fmt::Display for State {
#[derive(Debug, Clone, Copy)]
pub enum DockerControls {
Pause,
Unpause,
Restart,
Stop,
Start,
Stop,
Unpause,
}

impl DockerControls {
pub const fn get_color(self) -> Color {
match self {
Self::Pause => Color::Yellow,
Self::Restart => Color::Magenta,
Self::Start => Color::Green,
Self::Stop => Color::Red,
Self::Restart => Color::Magenta,
Self::Pause => Color::Yellow,
Self::Unpause => Color::Blue,
}
}
Expand All @@ -237,10 +237,10 @@ impl fmt::Display for DockerControls {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let disp = match self {
Self::Pause => "pause",
Self::Unpause => "unpause",
Self::Restart => "restart",
Self::Stop => "stop",
Self::Start => "start",
Self::Stop => "stop",
Self::Unpause => "unpause",
};
write!(f, "{}", disp)
}
Expand Down
8 changes: 4 additions & 4 deletions src/app_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::fmt;
#[allow(unused)]
#[derive(Debug, Clone, Copy)]
pub enum AppError {
DockerCommand(DockerControls),
DockerConnect,
DockerInterval,
InputPoll,
DockerCommand(DockerControls),
MouseCapture(bool),
Terminal,
}
Expand All @@ -17,15 +17,15 @@ pub enum AppError {
impl fmt::Display for AppError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::DockerCommand(s) => write!(f, "Unable to {} container", s),
Self::DockerConnect => write!(f, "Unable to access docker daemon"),
Self::DockerInterval => write!(f, "Docker update interval needs to be greater than 0"),
Self::InputPoll => write!(f, "Unable to poll user input"),
Self::Terminal => write!(f, "Unable to draw to terminal"),
Self::DockerCommand(s) => write!(f, "Unable to {} container", s),
Self::MouseCapture(x) => {
let reason = if *x { "en" } else { "dis" };
let reason = if *x { "en" } else { "dis" };
write!(f, "Unbale to {}able mouse capture", reason)
}
Self::Terminal => write!(f, "Unable to draw to terminal"),
}
}
}
11 changes: 6 additions & 5 deletions src/docker_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl DockerData {
.cpu_usage
.percpu_usage
.as_ref()
.map_or_else(|| 0, std::vec::Vec::len) as u64
.map_or(0, std::vec::Vec::len) as u64
}) as f64;
if system_delta > 0.0 && cpu_delta > 0.0 {
cpu_percentage = (cpu_delta / system_delta) * online_cpus * 100.0;
Expand Down Expand Up @@ -122,10 +122,11 @@ impl DockerData {
let cpu_stats = Self::calculate_usage(&stats);

let (rx, tx) = if let Some(key) = op_key {
match stats.networks.unwrap_or_default().get(&key) {
Some(data) => (data.rx_bytes, data.tx_bytes),
None => (0, 0),
}
stats
.networks
.unwrap_or_default()
.get(&key)
.map_or((0, 0), |f| (f.rx_bytes, f.tx_bytes))
} else {
(0, 0)
};
Expand Down

0 comments on commit 5660b34

Please sign in to comment.