#bytes #size #humanize #human #parser

parse-size

Parse byte size into integer accurately

1 stable release

1.0.0 May 4, 2021

#7 in #humanize

Download history 205/week @ 2022-03-06 186/week @ 2022-03-13 182/week @ 2022-03-20 185/week @ 2022-03-27 236/week @ 2022-04-03 262/week @ 2022-04-10 134/week @ 2022-04-17 273/week @ 2022-04-24 219/week @ 2022-05-01 231/week @ 2022-05-08 223/week @ 2022-05-15 174/week @ 2022-05-22 159/week @ 2022-05-29 324/week @ 2022-06-05 383/week @ 2022-06-12 482/week @ 2022-06-19

1,357 downloads per month
Used in 2 crates

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