https://github.com/jacoblightning/prefix_parser
A rust library to parse binary and SI number prefixes
https://github.com/jacoblightning/prefix_parser
binary binary-prefix parser prefix rust rust-crate rust-library si si-prefixes
Last synced: 2 months ago
JSON representation
A rust library to parse binary and SI number prefixes
- Host: GitHub
- URL: https://github.com/jacoblightning/prefix_parser
- Owner: Jacoblightning
- License: apache-2.0
- Created: 2025-07-07T10:03:31.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-07-07T11:00:46.000Z (3 months ago)
- Last Synced: 2025-07-07T11:09:05.283Z (3 months ago)
- Topics: binary, binary-prefix, parser, prefix, rust, rust-crate, rust-library, si, si-prefixes
- Language: Rust
- Homepage: https://crates.io/crates/prefix_parser
- Size: 14.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# 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.
```rust
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.