1 stable release

1.0.0 May 4, 2021

#852 in Parser implementations

Download history 23294/week @ 2023-12-13 12614/week @ 2023-12-20 9961/week @ 2023-12-27 20237/week @ 2024-01-03 22004/week @ 2024-01-10 28687/week @ 2024-01-17 29181/week @ 2024-01-24 30708/week @ 2024-01-31 27584/week @ 2024-02-07 25034/week @ 2024-02-14 23359/week @ 2024-02-21 24813/week @ 2024-02-28 31338/week @ 2024-03-06 30768/week @ 2024-03-13 26316/week @ 2024-03-20 21141/week @ 2024-03-27

114,469 downloads per month
Used in 20 crates (12 directly)

MIT license

24KB
330 lines

parse-size

Crates.io docs.rs Build status MIT License

parse-size is an accurate, customizable, allocation-free library for parsing byte size into integer.

use parse_size::parse_size;

assert_eq!(parse_size("0.2 MiB"), Ok(209715));
assert_eq!(parse_size("14.2e+8"), Ok(14_2000_0000));

Features

  • Supports both binary and decimal based prefix up to exabytes.
  • Numbers can be fractional and/or in scientific notation. parse-size can accurately parse the input using the full 64-bit precision.
  • The unit is case-insensitive. The "B" suffix is also optional (1 KiB = 1 kib = 1Ki).
  • Fractional bytes are allowed, and rounded to nearest integer (2.5B = 3).
  • Underscores and spaces in the numbers are ignored to support digit grouping (123_456 = 123456).
  • Conventional units (KB, GB, ...) can be configured to use the binary system.
  • #![no_std]-capable, no dependencies, and uses no heap allocation.

No runtime deps

Features