Skip to main content

parse_byte_count

Function parse_byte_count 

Source
pub fn parse_byte_count(s: &str) -> Result<u64>
Expand description

Parse a byte-count token (500, 500B, 10KB, 2MB, 1GB, 1TB decimal; 10KIB, 2MIB, 1GIB, 1TIB binary; a bare number means bytes). Digit runs may group with _ separators (1_000_000), Rust-literal style: leading, trailing, and doubled separators fail. One optional space may separate the number from its unit (1 GB); anything more stays rejected, and bare DSL tokens still split upstream (this covers quoted strings, variables, and flag values). Fractions stay rejected by design (1.5GB fails: float parsing cannot hold exact byte boundaries past 2^53, and every sub-unit has an exact integer spelling like 1500MB). Matching is case-insensitive (1gb, 1GB, and 1Gb agree), mirroring parse_duration: digits only, no fractions, no signs.