| Crates.io | humanbyte |
| lib.rs | humanbyte |
| version | 0.2.1 |
| created_at | 2025-02-05 06:01:25.438115+00 |
| updated_at | 2025-06-06 02:42:17.594505+00 |
| description | A procedural macro for deriving human readable byte functions |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1543604 |
| size | 10,980 |
HumanByte is a procedural macro crate for deriving HumanByte functions for new types of the form NewType(u64). It is
inspired by the bytesize crate (which is replicated here by our example [bytescale] crate).
It provides human-friendly way of constructing and displaying the type with byte units.
Add this to your Cargo.toml:
[dependencies]
humanbyte = { version = "0.1", features = ["serde"] }
[dependencies]
humanbyte = { version = "0.1" }
[dependencies]
humanbyte = { version = "0.1", no-default-features = true }
Define your new type and derive HumanByte for it. This will derive all the necessary functions for your new type. You
can then use it like this:
use humanbyte_derive::HumanByte;
#[derive(HumanByte)]
pub struct NewType(u64);
fn main() {
let size = NewType::kib(1);
assert_eq!(size.to_string(), "1.0 KiB");
}
See the documentation for bytescale to see more examples of what you can do with the HumanByte new type.
In addition, if you only want some of the HumanByte functions derived, you can use any of the following derives in an a la carte fashion:
serde feature)