mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-29 07:03:54 +00:00
2d41333117
- s/to_owned/to_string/g - TotalEq/TotalOrd changes - snake_case of identifiers
25 lines
637 B
Rust
25 lines
637 B
Rust
static METRIC_PREFIXES: &'static [&'static str] = &[
|
|
"", "K", "M", "G", "T", "P", "E", "Z", "Y"
|
|
];
|
|
|
|
static IEC_PREFIXES: &'static [&'static str] = &[
|
|
"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"
|
|
];
|
|
|
|
fn format_bytes(mut amount: u64, kilo: u64, prefixes: &[&str]) -> String {
|
|
let mut prefix = 0;
|
|
while amount > kilo {
|
|
amount /= kilo;
|
|
prefix += 1;
|
|
}
|
|
format!("{}{}", amount, prefixes[prefix])
|
|
}
|
|
|
|
pub fn format_IEC_bytes(amount: u64) -> String {
|
|
format_bytes(amount, 1024, IEC_PREFIXES)
|
|
}
|
|
|
|
pub fn format_metric_bytes(amount: u64) -> String {
|
|
format_bytes(amount, 1000, METRIC_PREFIXES)
|
|
}
|