refactor: map_or_else to map_or
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
+4
-4
@@ -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,
|
||||
}
|
||||
@@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user