2 stable releases

1.1.0 Sep 17, 2024
1.0.0 May 4, 2021

#192 in Parser implementations

Download history 35248/week @ 2024-08-04 32193/week @ 2024-08-11 35989/week @ 2024-08-18 37306/week @ 2024-08-25 35058/week @ 2024-09-01 34732/week @ 2024-09-08 32381/week @ 2024-09-15 39990/week @ 2024-09-22 35381/week @ 2024-09-29 33950/week @ 2024-10-06 37719/week @ 2024-10-13 40143/week @ 2024-10-20 36692/week @ 2024-10-27 37368/week @ 2024-11-03 34530/week @ 2024-11-10 39715/week @ 2024-11-17

149,450 downloads per month
Used in 26 crates (19 directly)

MIT license

25KB
369 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.5 KiB = 2560, 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