pub fn pretty_size_with_options(
size_in_bytes: u64,
options: impl Into<PrettySizeOptions>,
) -> StringExpand description
Formats a byte size as a pretty, fixed-width (9 char) string with unit alignment. The output format is tailored to align nicely in monospaced tables.
- Number is always 6 character, always right aligned.
- Empty char
- Unit is always 2 chars, left aligned. So, for Byte, “B”, it will be “B “
- When below 1K Byte, do not have any digits
- Otherwise, always 2 digit, rounded
§PrettySizeOptions
lowest_unitDefine the lowest unit to consider, For example, ifMB, then, B and KB will be expressed in decimal following the formatting rules.
NOTE: From String, &str, .. are implemented, so PrettySizeOptions::from("MB") will default to
PrettySizeOptions { lowest_unit: SizeUnit::MB } (if string not match, will default to SizeUnit::MB)
§Examples
777 -> " 777 B "
8777 -> " 8.78 KB"
88777 -> " 88.78 KB"
888777 -> "888.78 KB"
2_345_678_900 -> " 2.35 GB"
NOTE: if in simple-fs, migh call it pretty_size()