1 stable release

1.0.0 May 4, 2021

#676 in Parser implementations

Download history 569/week @ 2022-11-30 749/week @ 2022-12-07 931/week @ 2022-12-14 435/week @ 2022-12-21 396/week @ 2022-12-28 643/week @ 2023-01-04 767/week @ 2023-01-11 642/week @ 2023-01-18 980/week @ 2023-01-25 1310/week @ 2023-02-01 1061/week @ 2023-02-08 900/week @ 2023-02-15 1092/week @ 2023-02-22 1676/week @ 2023-03-01 3330/week @ 2023-03-08 2513/week @ 2023-03-15

8,759 downloads per month
Used in 11 crates (6 directly)

MIT license

23KB
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

  • std