-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c70ce42
commit 91c3459
Showing
5 changed files
with
91 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
use ::std::fmt; | ||
|
||
// Should we make a `DisplayMode` enum with `Rate` and `Total`? | ||
// Instead of the ambiguous bool? | ||
|
||
// This might be better as a traditional struct now? | ||
pub struct DisplayBandwidth(pub f64, pub bool); | ||
pub struct DisplayBandwidth { | ||
pub bandwidth: f64, | ||
pub as_rate: bool, | ||
} | ||
|
||
impl fmt::Display for DisplayBandwidth { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let suffix = if self.1 { "" } else { "ps" }; // Should this be the other way around? | ||
if self.0 > 999_999_999.0 { | ||
write!(f, "{:.2}GB{}", self.0 / 1_000_000_000.0, suffix) | ||
} else if self.0 > 999_999.0 { | ||
write!(f, "{:.2}MB{}", self.0 / 1_000_000.0, suffix) | ||
} else if self.0 > 999.0 { | ||
write!(f, "{:.2}KB{}", self.0 / 1000.0, suffix) | ||
let suffix = if self.as_rate { "" } else { "ps" }; | ||
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, "{}B{}", self.0, suffix) | ||
write!(f, "{}B{}", self.bandwidth, suffix) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters