Skip to main content

Module fmt

Module fmt 

Source
Expand description

Rendering a quantity in the form an operator wrote it.

uom’s own formatting needs the unit named at the call site (size.into_format_args(mebibyte, Abbreviation)). That is the wrong shape for a log line or a config dump, where the magnitude decides the unit. Human picks the unit for you: 536870912 bytes prints as 512MiB, 604800 seconds as 7d, 1536 bytes as 1.5KiB.

§Exactness

Sizes, time extents, and byte rates round-trip. crate::parse reads back whatever these types print as the same value. That requirement picks the unit. Human uses the largest unit that leaves the magnitude at or above one and representable in at most three decimal places, so 1TiB + 1B prints as 1099511627777B and does not round to 1TiB. A quantity that is not a whole number of base units, or is too large for that arithmetic, prints its base-unit value, which also reads back exactly.

Fractions and event rates render to nine decimal places and are for display only. A non-finite quantity prints its raw value and base unit, for diagnostics.

Structs§

HumanByteRate
ByteRate rendered as a binary size over a second.
HumanByteSize
ByteSize rendered in binary size units.
HumanFrequency
Frequency rendered as events per second.
HumanRatio
Ratio rendered as a percentage.
HumanTime
Time rendered in time units, from days down to nanoseconds.

Traits§

Human
A quantity that renders itself the way an operator would write it.