summaryrefslogtreecommitdiff
path: root/src/utils/size_display.rs
blob: 3e2bc29ed38a0c8fddad349c14859fdb3f5b3d60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pub fn size_display<'a>(total_bytes: usize) -> (f64, &'a str) {
    let total_bytes = total_bytes as f64;
    if total_bytes >= 1024.0 * 1024.0 * 1024.0 * 1024.0 {
        (total_bytes / (1024.0 * 1024.0 * 1024.0 * 1024.0), "TB")
    } else if total_bytes >= 1024.0 * 1024.0 * 1024.0 {
        (total_bytes / (1024.0 * 1024.0 * 1024.0), "GB")
    } else if total_bytes >= 1024.0 * 1024.0 {
        (total_bytes / (1024.0 * 1024.0), "MB")
    } else if total_bytes >= 1024.0 {
        (total_bytes / 1024.0, "KB")
    } else {
        (total_bytes, "B")
    }
}