human-bytesize-procmacro
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:
[]
= "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;
assert_eq!;
assert_eq!;
let variable = 160;
assert_eq!;
For more usage examples, refer to the documentation available at docs.rs.
Supported units
| Unit Code | Unit Name | Bytes |
|---|---|---|
| B | Byte | $10000 = 10240 = 1$ |
| K or KB | Kilobyte | $1000^1 = 1000$ |
| Ki or KiB | Kibibyte | $1024^1 = 1024$ |
| M or MB | Megabyte | $1000^2 = 1000 \cdot 1000$ |
| Mi or MiB | Mebibyte | $1024^2 = 1024 \cdot 1024$ |
| G or GB | Gigabyte | $1000^3 = 1000 \cdot 1000 \cdot 1000$ |
| Gi or GiB | Gibibyte | $1024^3 = 1024 \cdot 1024 \cdot 1024$ |
| T or TB | Terabyte | $1000^4 = 1000 \cdot 1000 \cdot 1000 \cdot 1000$ |
| Ti or TiB | Tebibyte | $1024^4 = 1024 \cdot 1024 \cdot 1024 \cdot 1024$ |
| P or PB | Petabyte | $1000^5 = 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000$ |
| Pi or PiB | Pebibyte | $1024^5 = 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024$ |
| E or EB | Exabyte | $1000^6 = 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000$ |
| Ei or EiB | Exbibyte | $1024^6 = 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024$ |
| Z or ZB | Zettabyte | $1000^7 = 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000$ |
| Zi or ZiB | Zebibyte | $1024^7 = 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024$ |
| Y or YB | Yottabyte | $1000^8 = 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000 \cdot 1000$ |
| Yi or YiB | Yobibyte | $1024^8 = 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024 \cdot 1024$ |
License
This crate is licensed under the MIT License.