Crate human_bytesize_procmacro

Crate human_bytesize_procmacro 

Source
Expand description

A procedural macro for parsing and computing human-readable byte sizes with support for various units like KB, KiB, MB, MiB, and more.

§Setup

To use this crate, add the following entry to your Cargo.toml file in the dependencies section:

[dependencies]
human-bytesize-procmacro = "0.0.0"

Alternatively, you can use the cargo add subcommand:

cargo add human-bytesize-procmacro

§Usage

Use the human_bytesize! macro to convert human-readable byte sizes into their byte equivalents by passing a size with its unit:

use human_bytesize_procmacro::human_bytesize;

assert_eq!(human_bytesize!(10KB), 10 * 1000);
assert_eq!(human_bytesize!(16 KiB), 16 * 1024);
let variable = 160;
assert_eq!(human_bytesize!({ variable } MB), variable * 1000 * 1000);

§Supported units

§Decimal Units (Base 10)

  • B (Byte)
  • K, KB (Kilobyte)
  • M, MB (Megabyte)
  • G, GB (Gigabyte)
  • T, TB (Terabyte)
  • P, PB (Petabyte)
  • E, EB (Exabyte)
  • Z, ZB (Zettabyte)
  • Y, YB (Yottabyte)

§Binary Units (Base 2)

  • B (Byte)
  • Ki, KiB (Kibibyte)
  • Mi, MiB (Mebibyte)
  • Gi, GiB (Gibibyte)
  • Ti, TiB (Tebibyte)
  • Pi, PiB (Pebibyte)
  • Ei, EiB (Exbibyte)
  • Zi, ZiB (Zebibyte)
  • Yi, YiB (Yobibyte)

§License

This crate is licensed under the MIT License.

Macros§

human_bytesize
A procedural macro for converting human-readable byte size expressions into their corresponding byte values at compile time.