#byte-size #byte #size #human #serde #units

no-std huby

A simple crate (supporting serde) to handle byte sizes as human

7 releases

0.2.0 Nov 5, 2024
0.1.5 Jul 12, 2024

#2139 in Parser implementations

Download history 21/week @ 2024-11-20 29/week @ 2024-11-27 17/week @ 2024-12-04 24/week @ 2024-12-11 6/week @ 2024-12-18 4/week @ 2025-01-01 10/week @ 2025-01-08 3/week @ 2025-01-15 1/week @ 2025-01-22 7/week @ 2025-01-29 12/week @ 2025-02-05 45/week @ 2025-02-12 122/week @ 2025-02-19 84/week @ 2025-02-26 37/week @ 2025-03-05

291 downloads per month
Used in firo

GPL-3.0 license

20KB
382 lines

GitHub Actions Workflow Status Crates.io Version docs.rs

Human Bytes

huby is a library for easily handling byte sizes.

Crate features

Default

  • std: Enable feature depending on the Rust standard library

Optional

  • serde: Enable serialization/deserialization via serde.

Examples

Basics

use huby::ByteSize;

assert_eq!("42.42 KB".parse::<ByteSize>().unwrap(), ByteSize::from_kb_f64(42.42));

Use with serde

use huby::ByteSize;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
pub struct Logger {
    path: String,
    max_size: ByteSize,
}

let logger = Logger {
    path: "some_path".into(),
    max_size: ByteSize::from_gb(1),
};

// Serialize
let j = serde_json::to_string(&logger).unwrap();
assert_eq!(r#"{"path":"some_path","max_size":"1GB"}"#, j);

// Deserialize
let l: Logger = serde_json::from_str(&j).unwrap();
assert_eq!(l.max_size, ByteSize::from_mb(1024));

Dependencies

~165KB