Humanize Bytes
Create a human-readable string representation of a number of bytes either in binary or decimal units (SI or IEC).
https://en.wikipedia.org/wiki/Binary_prefix
1 KB = 1000 B 1 KiB = 1024 B
use ;
println!; // 0 B
println!; // 512 B
println!; // 1023 B
println!; // 1 KiB
println!; // 1 KiB
println!; // 1.1 KiB
println!; // 1023.9 kB
println!; // 1 MB
println!; // 0 B
println!; // 512 B
println!; // 999 B
println!; // 1 kB
println!; // 1 kB
println!; // 1.1 kB
println!; // 999.9 kB
println!; // 1 MB
println!; // 0
println!; // 512
println!; // 999
println!; // 1 k
println!; // 1 k
println!; // 1.1 k
println!; // 999.9 k
println!; // 1 M
Implementation Details
This crate has one dependency, smartstring, and does not allocate because all formatting fits within the MAX_INLINE limit for a SmartString<LazyCompact>. Both macros return a SmartString<LazyCompact>, which looks/feels just like a normal String.