#deserialize #byte #serde

byte-unit-serde

De/serialization functions for byte-unit crate

2 releases

0.1.1 Dec 4, 2024
0.1.0 Feb 17, 2024

#1048 in Encoding

Download history 424/week @ 2024-12-08 311/week @ 2024-12-15 292/week @ 2024-12-22 204/week @ 2024-12-29 425/week @ 2025-01-05 545/week @ 2025-01-12 339/week @ 2025-01-19 311/week @ 2025-01-26 328/week @ 2025-02-02 221/week @ 2025-02-09 269/week @ 2025-02-16 160/week @ 2025-02-23 362/week @ 2025-03-02 327/week @ 2025-03-09 448/week @ 2025-03-16 668/week @ 2025-03-23

1,808 downloads per month

MIT/Apache

8KB
108 lines

byte-unit-serde

tests crates.io Documentation MIT/Apache-2 licensed

This crate provides de/serialization helper for byte-unit crate to use in combination with serde's with-annotation. This might be useful because it hides a byte-unit crate as an implementation details and allows use the simple u64 type instead. In other words, by using this crate, your code will not depend on the byte-unit crate.

Example

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct Foo {
    #[serde(with = "byte_unit_serde")]
    max_size: u64,
    /// This module also supports an optional values.
    #[serde(default, with = "byte_unit_serde")]
    min_size: Option<u64>,
}

The idea of this crate is heavily inspired by humantime-serde.

Dependencies

~1–1.6MB
~34K SLoC