#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

#1069 in Encoding

Download history 23/week @ 2024-06-03 40/week @ 2024-06-10 28/week @ 2024-06-17 36/week @ 2024-06-24 21/week @ 2024-07-01 77/week @ 2024-07-08 67/week @ 2024-07-15 44/week @ 2024-07-22 61/week @ 2024-07-29 62/week @ 2024-08-05 53/week @ 2024-08-12 38/week @ 2024-08-19 47/week @ 2024-08-26 73/week @ 2024-09-02 54/week @ 2024-09-09 56/week @ 2024-09-16

232 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.2–1.8MB
~37K SLoC