diff options
Diffstat (limited to 'src/display/components/display_bandwidth.rs')
-rw-r--r-- | src/display/components/display_bandwidth.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/display/components/display_bandwidth.rs b/src/display/components/display_bandwidth.rs index 31653e6..dcc204c 100644 --- a/src/display/components/display_bandwidth.rs +++ b/src/display/components/display_bandwidth.rs @@ -1,17 +1,21 @@ use ::std::fmt; -pub struct DisplayBandwidth(pub f64); +pub struct DisplayBandwidth { + pub bandwidth: f64, + pub as_rate: bool, +} impl fmt::Display for DisplayBandwidth { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if self.0 > 999_999_999.0 { - write!(f, "{:.2}GBps", self.0 / 1_000_000_000.0) - } else if self.0 > 999_999.0 { - write!(f, "{:.2}MBps", self.0 / 1_000_000.0) - } else if self.0 > 999.0 { - write!(f, "{:.2}KBps", self.0 / 1000.0) + let suffix = if self.as_rate { "ps" } else { "" }; + if self.bandwidth > 999_999_999.0 { + write!(f, "{:.2}GB{}", self.bandwidth / 1_000_000_000.0, suffix) + } else if self.bandwidth > 999_999.0 { + write!(f, "{:.2}MB{}", self.bandwidth / 1_000_000.0, suffix) + } else if self.bandwidth > 999.0 { + write!(f, "{:.2}KB{}", self.bandwidth / 1000.0, suffix) } else { - write!(f, "{}Bps", self.0) + write!(f, "{}B{}", self.bandwidth, suffix) } } } |