Skip to main content

format_size

Function format_size 

Source
pub fn format_size(bytes: u64) -> String
Expand description

Renders a byte count the way a human reads it, for stuffr info.

The inverse of parse_size, and the two live in different crates but are tested together below so they cannot drift: anything this prints must parse back to the same value.

Lives in stuffr-core now, not here — whole-branch review LOW-5: three codecs in stuffr-formats had their own, differently-united renderings of the identical “declared size vs. configured limit” message this function was already written for, and stuffr-formats cannot depend on this crate to reach it. See stuffr_core::size’s module doc for the full reasoning. Re-exported here so every existing caller in this crate (main.rs’s stuffr_cli::size::format_size, this module’s own tests) keeps working unchanged. Renders a byte count the way a human reads it.

Exact multiples get a bare suffix (256 MiB); anything else keeps one decimal (1.5 GiB), because rounding a limit or a declared size to a tidy figure would be actively unhelpful in a message someone is using to size a flag.