Format a byte size as a human-readable string (e.g., "64 KB", "1.2 MB").
(bytes: usize)
| 663 | |
| 664 | /// Format a byte size as a human-readable string (e.g., "64 KB", "1.2 MB"). |
| 665 | fn format_size(bytes: usize) -> String { |
| 666 | if bytes >= 1024 * 1024 { |
| 667 | format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0)) |
| 668 | } else if bytes >= 1024 { |
| 669 | format!("{:.1} KB", bytes as f64 / 1024.0) |
| 670 | } else { |
| 671 | format!("{} B", bytes) |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | // ═══════════════════════════════════════════════════════════════════════ |
| 676 | // Tests |
nothing calls this directly
no outgoing calls
no test coverage detected