Crates.io | bytesize-serde |
lib.rs | bytesize-serde |
version | 0.2.1 |
source | src |
created_at | 2022-04-27 11:25:15.147762 |
updated_at | 2022-12-02 21:38:45.847253 |
description | Alternative serde implementation for bytesize crate based on its FromStr |
homepage | https://github.com/l4l/bytesize-serde |
repository | https://github.com/l4l/bytesize-serde |
max_upload_size | |
id | 575991 |
size | 6,230 |
Alternative serde implementation for bytesize
crate based on its FromStr
implementation for human-readable serializers.
use bytesize::ByteSize;
use serde::{Serialize, Deserialize};
# fn main() {
#[derive(Serialize, Deserialize)]
struct T {
#[serde(with = "bytesize_serde")]
x: ByteSize,
}
let t: T = serde_json::from_str(r#"{ "x": "5 MB" }"#).unwrap();
assert_eq!(t.x, "5 MB".parse::<ByteSize>().unwrap());
# }