# human-bytesize-procmacro
[](https://crates.io/crates/human-bytesize-procmacro)
[](https://github.com/ventaquil/human-bytesize-procmacro/actions/workflows/rust.yml)
[](https://docs.rs/human-bytesize-procmacro/)
[](https://github.com/ventaquil/human-bytesize-procmacro/blob/master/Cargo.toml)
[](https://deps.rs/crate/human-bytesize-procmacro/0.0.0)
[](https://github.com/rust-secure-code/safety-dance)
[](https://github.com/ventaquil/human-bytesize-procmacro/blob/master/LICENSE)
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:
```toml
[dependencies]
human-bytesize-procmacro = "0.0.0"
```
Alternatively, you can use the [`cargo add`](https://doc.rust-lang.org/cargo/commands/cargo-add.html) subcommand:
```shell
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:
```rust
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);
```
For more usage examples, refer to the documentation available at [docs.rs](https://docs.rs/human-bytesize-procmacro/).
## Supported units
| B | Byte | $1000^0 = 1024^0 = 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.