prefix_parser 0.2.0

A parser for numbers with binary prefixes on the end. EX: Turning 1KB into 1000.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 36.32 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 894.8 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Jacoblightning/prefix_parser
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Jacoblightning

Prefix Parser

A parser for numbers with a binary/SI prefix on the end.

Usage:

call prefix_parser::parse_prefixes with the prefixed number to parse.

let parsed = prefix_parser::parse_prefixes("216MiB")?;

// 226492416 == 1024^2 * 216, so 226492416 is 216MiB
assert_eq!(parsed, 226492416);

Things to note:

  • If no prefix is specified, the value is just converted to a number and returned.
  • Capitalization is ignored. To differentiate between SI and binary, use MB vs MiB, KB vs KiB, etc...
  • If just the first letter is specified, it is assumed to be in binary format (1k is 1024, not 1000).
  • All of b, bb, and bib are allowed and valid, although they just keep the number as is.