(bytes: u64)
| 92 | } |
| 93 | |
| 94 | fn format_size(bytes: u64) -> String { |
| 95 | if bytes < 1024 { |
| 96 | format!("{}B", bytes) |
| 97 | } else if bytes < 1024 * 1024 { |
| 98 | format!("{:.1}KB", bytes as f64 / 1024.0) |
| 99 | } else if bytes < 1024 * 1024 * 1024 { |
| 100 | format!("{:.1}MB", bytes as f64 / (1024.0 * 1024.0)) |
| 101 | } else { |
| 102 | format!("{:.1}GB", bytes as f64 / (1024.0 * 1024.0 * 1024.0)) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | #[cfg(test)] |
| 107 | mod tests { |