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§
- Parse
Error - 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.