1 stable release

1.0.0 May 4, 2021

#853 in Parser implementations

Download history 24434/week @ 2024-02-27 30831/week @ 2024-03-05 30505/week @ 2024-03-12 26544/week @ 2024-03-19 26160/week @ 2024-03-26 31680/week @ 2024-04-02 29092/week @ 2024-04-09 30520/week @ 2024-04-16 39351/week @ 2024-04-23 36058/week @ 2024-04-30 33201/week @ 2024-05-07 38680/week @ 2024-05-14 37617/week @ 2024-05-21 41041/week @ 2024-05-28 39407/week @ 2024-06-04 29968/week @ 2024-06-11

154,009 downloads per month
Used in 22 crates (14 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