| Crates.io | bytesize |
| lib.rs | bytesize |
| version | 2.1.0 |
| created_at | 2015-04-19 04:55:38.917419+00 |
| updated_at | 2025-09-15 08:39:40.271542+00 |
| description | Semantic wrapper for byte count representations |
| homepage | |
| repository | https://github.com/bytesize-rs/bytesize |
| max_upload_size | |
| id | 1894 |
| size | 71,941 |
ByteSize is a semantic wrapper for byte count representations.
Features:
ByteSize type which presents size units convertible to different size units.ByteSize.FromStr impl for ByteSize, allowing for parsing string size representations like "1.5KiB" and "521TiB".Construction using SI or IEC helpers.
use bytesize::ByteSize;
assert!(ByteSize::kib(4) > ByteSize::kb(4));
Display as human-readable string.
use bytesize::ByteSize;
assert_eq!("518.0 GiB", ByteSize::gib(518).display().iec().to_string());
assert_eq!("556.2 GB", ByteSize::gib(518).display().si().to_string());
assert_eq!("518.0G", ByteSize::gib(518).display().iec_short().to_string());
Arithmetic operations are supported.
use bytesize::ByteSize;
let plus = ByteSize::mb(1) + ByteSize::kb(100);
println!("{plus}");
let minus = ByteSize::tb(1) - ByteSize::gb(4);
assert_eq!(ByteSize::gb(996), minus);