#[must_use] pub fn human_size(size: u64) -> String {
const KIB: f64 = 1024.0;
const MIB: f64 = KIB * 1024.0;
const GIB: f64 = MIB * 1024.0;
const TIB: f64 = GIB * 1024.0;
match size {
0..=0x7FF => format!("{size} B"), 0x400..=0xFFFFF => format!("{} KiB", size / 1024),
0x100000..=0x3FFFFFFF => format_number(size as f64 / MIB, "MiB"),
0x40000000..=0xFFFFFFFFFF => format_number(size as f64 / GIB, "GiB"),
_ => format_number(size as f64 / TIB, "TiB"),
}
}
fn format_number(value: f64, unit: &str) -> String {
if value.fract() == 0.0 {
format!("{value:.0} {unit}")
} else {
format!("{value:.1} {unit}")
}
}