refactor: derive Default for CpuStats + ByteStats
This commit is contained in:
@@ -253,7 +253,7 @@ pub trait Stats {
|
|||||||
/// Struct for frequently updated CPU stats
|
/// Struct for frequently updated CPU stats
|
||||||
/// So can use custom display formatter
|
/// So can use custom display formatter
|
||||||
/// Use trait Stats for use as generic in draw_chart function
|
/// Use trait Stats for use as generic in draw_chart function
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Default, Clone, Copy)]
|
||||||
pub struct CpuStats {
|
pub struct CpuStats {
|
||||||
value: f64,
|
value: f64,
|
||||||
}
|
}
|
||||||
@@ -306,7 +306,7 @@ impl fmt::Display for CpuStats {
|
|||||||
/// Struct for frequently updated memory usage stats
|
/// Struct for frequently updated memory usage stats
|
||||||
/// So can use custom display formatter
|
/// So can use custom display formatter
|
||||||
/// Use trait Stats for use as generic in draw_chart function
|
/// Use trait Stats for use as generic in draw_chart function
|
||||||
#[derive(Debug, Clone, Copy, Eq)]
|
#[derive(Debug, Default, Clone, Copy, Eq)]
|
||||||
pub struct ByteStats {
|
pub struct ByteStats {
|
||||||
value: u64,
|
value: u64,
|
||||||
}
|
}
|
||||||
@@ -390,11 +390,11 @@ impl ContainerItem {
|
|||||||
image,
|
image,
|
||||||
last_updated: 0,
|
last_updated: 0,
|
||||||
logs: StatefulList::new(vec![]),
|
logs: StatefulList::new(vec![]),
|
||||||
mem_limit: ByteStats::new(0),
|
mem_limit: ByteStats::default(),
|
||||||
mem_stats: VecDeque::with_capacity(60),
|
mem_stats: VecDeque::with_capacity(60),
|
||||||
name,
|
name,
|
||||||
rx: ByteStats::new(0),
|
rx: ByteStats::default(),
|
||||||
tx: ByteStats::new(0),
|
tx: ByteStats::default(),
|
||||||
state,
|
state,
|
||||||
status,
|
status,
|
||||||
}
|
}
|
||||||
@@ -404,7 +404,7 @@ impl ContainerItem {
|
|||||||
fn max_cpu_stats(&self) -> CpuStats {
|
fn max_cpu_stats(&self) -> CpuStats {
|
||||||
match self.cpu_stats.iter().max() {
|
match self.cpu_stats.iter().max() {
|
||||||
Some(value) => *value,
|
Some(value) => *value,
|
||||||
None => CpuStats::new(0.0),
|
None => CpuStats::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,7 +412,7 @@ impl ContainerItem {
|
|||||||
fn max_mem_stats(&self) -> ByteStats {
|
fn max_mem_stats(&self) -> ByteStats {
|
||||||
match self.mem_stats.iter().max() {
|
match self.mem_stats.iter().max() {
|
||||||
Some(value) => *value,
|
Some(value) => *value,
|
||||||
None => ByteStats::new(0),
|
None => ByteStats::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -328,12 +328,12 @@ impl AppData {
|
|||||||
&container
|
&container
|
||||||
.cpu_stats
|
.cpu_stats
|
||||||
.back()
|
.back()
|
||||||
.unwrap_or(&CpuStats::new(0.0))
|
.unwrap_or(&CpuStats::default())
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
let mem_count = count(&format!(
|
let mem_count = count(&format!(
|
||||||
"{} / {}",
|
"{} / {}",
|
||||||
container.mem_stats.back().unwrap_or(&ByteStats::new(0)),
|
container.mem_stats.back().unwrap_or(&ByteStats::default()),
|
||||||
container.mem_limit
|
container.mem_limit
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ pub fn containers<B: Backend>(
|
|||||||
|
|
||||||
let mems = format!(
|
let mems = format!(
|
||||||
"{:>1} / {:>1}",
|
"{:>1} / {:>1}",
|
||||||
i.mem_stats.back().unwrap_or(&ByteStats::new(0)),
|
i.mem_stats.back().unwrap_or(&ByteStats::default()),
|
||||||
i.mem_limit
|
i.mem_limit
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -155,7 +155,7 @@ pub fn containers<B: Backend>(
|
|||||||
format!(
|
format!(
|
||||||
"{}{:>width$}",
|
"{}{:>width$}",
|
||||||
MARGIN,
|
MARGIN,
|
||||||
i.cpu_stats.back().unwrap_or(&CpuStats::new(0.0)),
|
i.cpu_stats.back().unwrap_or(&CpuStats::default()),
|
||||||
width = &widths.cpu.1
|
width = &widths.cpu.1
|
||||||
),
|
),
|
||||||
state_style,
|
state_style,
|
||||||
|
|||||||
Reference in New Issue
Block a user