2 stable releases

1.1.0 Sep 17, 2024
1.0.0 May 4, 2021

#96 in Parser implementations

Download history 57343/week @ 2024-12-09 51123/week @ 2024-12-16 19312/week @ 2024-12-23 19786/week @ 2024-12-30 49730/week @ 2025-01-06 48429/week @ 2025-01-13 49854/week @ 2025-01-20 53085/week @ 2025-01-27 59351/week @ 2025-02-03 61585/week @ 2025-02-10 50967/week @ 2025-02-17 55765/week @ 2025-02-24 55611/week @ 2025-03-03 57776/week @ 2025-03-10 62755/week @ 2025-03-17 60584/week @ 2025-03-24

239,254 downloads per month
Used in 34 crates (25 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