Formats a byte count into a human-readable string (e.g. "798.0 MB").
(bytes: u64)
| 43 | |
| 44 | /// Formats a byte count into a human-readable string (e.g. "798.0 MB"). |
| 45 | pub fn format_bytes(bytes: u64) -> String { |
| 46 | if bytes >= 1_073_741_824 { |
| 47 | format!("{:.1} GB", bytes as f64 / 1_073_741_824.0) |
| 48 | } else if bytes >= 1_048_576 { |
| 49 | format!("{:.1} MB", bytes as f64 / 1_048_576.0) |
| 50 | } else if bytes >= 1024 { |
| 51 | format!("{:.1} KB", bytes as f64 / 1024.0) |
| 52 | } else { |
| 53 | format!("{bytes} B") |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /// Formats a number with comma separators (e.g. 243302 -> "243,302"). |
| 58 | pub fn format_number(n: u64) -> String { |
no outgoing calls
no test coverage detected