summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2022-11-20 02:21:20 -0500
committerGitHub <noreply@github.com>2022-11-20 02:21:20 -0500
commit63df220a38b13999294fd1187bf72082ebdd4ec7 (patch)
treea0970b92e60bdc4bca35a958727bda2523cfd2e6 /src/utils
parent6a0bf10760537193bb527d1ac0cd4ac13133da43 (diff)
other: clean up some strings (#904)
* other: clean up some strings * formatting
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/error.rs8
-rw-r--r--src/utils/gen_util.rs24
2 files changed, 13 insertions, 19 deletions
diff --git a/src/utils/error.rs b/src/utils/error.rs
index 603fabfc..fcb65e1b 100644
--- a/src/utils/error.rs
+++ b/src/utils/error.rs
@@ -100,13 +100,7 @@ impl From<regex::Error> for BottomError {
let err_str = err.to_string();
let error = err_str.split('\n').map(|s| s.trim()).collect::<Vec<_>>();
- BottomError::QueryError(
- format!(
- "Regex error: {}",
- error.last().unwrap_or(&"".to_string().as_str())
- )
- .into(),
- )
+ BottomError::QueryError(format!("Regex error: {}", error.last().unwrap_or(&"")).into())
}
}
diff --git a/src/utils/gen_util.rs b/src/utils/gen_util.rs
index 3a482937..ab8c8479 100644
--- a/src/utils/gen_util.rs
+++ b/src/utils/gen_util.rs
@@ -47,26 +47,26 @@ pub const LOG_TEBI_LIMIT_U32: u32 = 40;
/// Returns a tuple containing the value and the unit in bytes. In units of 1024.
/// This only supports up to a tebi. Note the "single" unit will have a space appended to match the others if
/// `spacing` is true.
-pub fn get_binary_bytes(bytes: u64) -> (f64, String) {
+pub fn get_binary_bytes(bytes: u64) -> (f64, &'static str) {
match bytes {
- b if b < KIBI_LIMIT => (bytes as f64, "B".to_string()),
- b if b < MEBI_LIMIT => (bytes as f64 / 1024.0, "KiB".to_string()),
- b if b < GIBI_LIMIT => (bytes as f64 / 1_048_576.0, "MiB".to_string()),
- b if b < TERA_LIMIT => (bytes as f64 / 1_073_741_824.0, "GiB".to_string()),
- _ => (bytes as f64 / 1_099_511_627_776.0, "TiB".to_string()),
+ b if b < KIBI_LIMIT => (bytes as f64, "B"),
+ b if b < MEBI_LIMIT => (bytes as f64 / 1024.0, "KiB"),
+ b if b < GIBI_LIMIT => (bytes as f64 / 1_048_576.0, "MiB"),
+ b if b < TERA_LIMIT => (bytes as f64 / 1_073_741_824.0, "GiB"),
+ _ => (bytes as f64 / 1_099_511_627_776.0, "TiB"),
}
}
/// Returns a tuple containing the value and the unit in bytes. In units of 1000.
/// This only supports up to a tera. Note the "single" unit will have a space appended to match the others if
/// `spacing` is true.
-pub fn get_decimal_bytes(bytes: u64) -> (f64, String) {
+pub fn get_decimal_bytes(bytes: u64) -> (f64, &'static str) {
match bytes {
- b if b < KILO_LIMIT => (bytes as f64, "B".to_string()),
- b if b < MEGA_LIMIT => (bytes as f64 / 1000.0, "KB".to_string()),
- b if b < GIGA_LIMIT => (bytes as f64 / 1_000_000.0, "MB".to_string()),
- b if b < TERA_LIMIT => (bytes as f64 / 1_000_000_000.0, "GB".to_string()),
- _ => (bytes as f64 / 1_000_000_000_000.0, "TB".to_string()),
+ b if b < KILO_LIMIT => (bytes as f64, "B"),
+ b if b < MEGA_LIMIT => (bytes as f64 / 1000.0, "KB"),
+ b if b < GIGA_LIMIT => (bytes as f64 / 1_000_000.0, "MB"),
+ b if b < TERA_LIMIT => (bytes as f64 / 1_000_000_000.0, "GB"),
+ _ => (bytes as f64 / 1_000_000_000_000.0, "TB"),
}
}