#deserialize #u64 #details #optional #values #hide #byte-unit

byte-unit-serde

De/serialization functions for byte-unit crate

1 unstable release

0.1.0 Feb 17, 2024

#802 in Encoding

Download history 140/week @ 2024-02-15 62/week @ 2024-02-22 37/week @ 2024-02-29 20/week @ 2024-03-07 23/week @ 2024-03-14 28/week @ 2024-03-21 49/week @ 2024-03-28 20/week @ 2024-04-04 4/week @ 2024-04-11 21/week @ 2024-04-18 31/week @ 2024-04-25

82 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.3–2MB
~39K SLoC