Skip to main content

format_size_fixed_rs

Function format_size_fixed_rs 

Source
pub fn format_size_fixed_rs(buf: &mut [u8], bytes: usize, unit: u8) -> &str
Expand description

Formats |bytes| as a human-readable string like “123.4k”. Units are in powers of 1024, so “K” is technically “kiB”, etc. Values smaller than “K” have the suffix “B”.

Exact multiples of a unit are displayed without a decimal; e.g., “17K” means the value is exactly 17 * 1024.

Otherwise, a decimal is present; e.g., “17.0K” means the value is (17 * 1024) +/- epsilon.

|unit| is the unit to use, as a u8 character (e.g. b’B’, b’K’, etc.). If zero, picks a natural unit for the size, ensuring at most four whole decimal places. If |unit| is unknown, the output will have a ‘?’ prefix but otherwise behave the same as |unit==0|.