$ byte-unit
v5.2.3A library for interacting with units of bytes.
Latest Update Summary
Crate
Name: byte-unit New version: 5.2.0 Release date: 2025-11-23T14:00:00.482050Z
Crate readme
Short description A library for interaction with units of bytes.
Long description
Byte Unit provides data types and functionality for storing and converting between various byte sizes. With default support for u64, it can represent sizes up to E, or up to Y if the u128 feature is enabled. The library includes units for bits and bytes, methods for arithmetic operations, and formatted output. It supports optional features like serde for serialization and no_std for compatibility with environments lacking standard library support.
Features • no_std compatibility • serde support • schemars support • rocket support • bit feature for bit representation
Code Examples Add to Cargo.toml
[dependencies.byte-unit]
version = "*"
default-features = false
features = ["byte"]
Creating Byte from u64
use byte_unit::Byte;
assert_eq!(15000, Byte::from_u64(15000).as_u64());
Parsing string to Byte
use byte_unit::Byte;
assert_eq!(50840000, Byte::parse_str("50.84 MB", true).unwrap().as_u64());
Arithmetic operations with Byte
use byte_unit::Byte;
let a = Byte::from_u64(15500);
let b = Byte::from_u64(500);
assert_eq!(16000, a.add(b).unwrap().as_u64());
Getting AdjustedByte Unit
use byte_unit::{Byte, Unit};
let byte = Byte::parse_str("123KiB", true).unwrap();
let adjusted_byte = byte.get_adjusted_unit(Unit::KB);
assert_eq!("125.952 KB", adjusted_byte.to_string());
Links • https://crates.io/crates/byte-unit • https://docs.rs/byte-unit
Release info
Release version: N/A
Release description N/A
Code Examples N/A
Patch update: 5.2.0 → 5.2.3
$ DOWNLOADS TREND
$ VERSION HISTORY
$ LINKS
$ INSTALL
cargo add byte-unitOr add to Cargo.toml: byte-unit = "5.2.3"