Crates.io | huby |
lib.rs | huby |
version | 0.2.0 |
source | src |
created_at | 2024-07-10 13:17:57.377268 |
updated_at | 2024-11-05 13:09:38.351585 |
description | A simple crate (supporting serde) to handle byte sizes as human |
homepage | |
repository | https://github.com/qjerome/human-bytes |
max_upload_size | |
id | 1298236 |
size | 54,581 |
huby
is a library for easily handling byte sizes.
std
: Enable feature depending on the Rust standard libraryserde
: Enable serialization/deserialization via serde.use huby::ByteSize;
assert_eq!("42.42 KB".parse::<ByteSize>().unwrap(), ByteSize::from_kb_f64(42.42));
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));