2 stable releases

1.1.0 Sep 17, 2024
1.0.0 May 4, 2021

#106 in Parser implementations

Download history 60998/week @ 2025-03-11 59832/week @ 2025-03-18 58962/week @ 2025-03-25 61041/week @ 2025-04-01 65768/week @ 2025-04-08 52683/week @ 2025-04-15 50841/week @ 2025-04-22 47891/week @ 2025-04-29 55437/week @ 2025-05-06 60376/week @ 2025-05-13 58257/week @ 2025-05-20 58324/week @ 2025-05-27 57932/week @ 2025-06-03 63480/week @ 2025-06-10 60607/week @ 2025-06-17 105854/week @ 2025-06-24

298,339 downloads per month
Used in 38 crates (29 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