Skip to main content

Module parse

Module parse 

Source
Expand description

Parsing the human forms of a quantity: 512MiB, 30s, 10MiB/s, 25%.

Operators write sizes and durations with units, and a config file that spells them out cannot be misread. Each parser takes a magnitude followed by a unit, with optional spaces between them. Each parser is case-insensitive, so 512MiB, 512 mib, and 512MIB are the same value.

A unit is required. 30 is not a duration, because whether it means 30 seconds or 30 milliseconds is the question the type must settle. The one exception is 0, which is unambiguous in any unit.

Binary and decimal size prefixes are distinct, as in the JEDEC/IEC split: KiB/MiB/GiB/TiB step by 1024, kB/MB/GB/TB by 1000.

The parsers do not accept exponent notation (1e6). A unit gives the scale.

Enums§

ParseError
Why a quantity string could not be read.

Functions§

byte_rate
A byte throughput: 10MiB/s, 1048576B/s, 64KiBps, 5 MB / sec.
byte_size
A byte count: 1024 → error, 1024B, 512MiB, 1.5 GiB, 2MB.
frequency
An event rate: 100/s, 2.5Hz, 60/min.
non_negative_byte_rate
A non-negative byte throughput.
non_negative_byte_size
A non-negative byte count.
non_negative_ratio
A non-negative dimensionless ratio.
non_negative_time
A non-negative time extent.
positive_byte_rate
A strictly positive byte throughput.
positive_byte_size
A strictly positive byte count.
positive_ratio
A strictly positive dimensionless ratio.
positive_time
A strictly positive time extent.
ratio
A dimensionless fraction: 25%, 0.25, 1.
time
A time extent: 30s, 500ms, 7d, 1.5h, 250 us.
unit_ratio
A dimensionless ratio in the inclusive range from zero through one.