bytesize-serde

Crates.iobytesize-serde
lib.rsbytesize-serde
version0.2.1
sourcesrc
created_at2022-04-27 11:25:15.147762
updated_at2022-12-02 21:38:45.847253
descriptionAlternative serde implementation for bytesize crate based on its FromStr
homepagehttps://github.com/l4l/bytesize-serde
repositoryhttps://github.com/l4l/bytesize-serde
max_upload_size
id575991
size6,230
Kitsu (l4l)

documentation

README

Alternative serde implementation for bytesize crate based on its FromStr implementation for human-readable serializers.

Usage

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());
# }
Commit count: 6

cargo fmt