byte-unit-serde

Crates.iobyte-unit-serde
lib.rsbyte-unit-serde
version0.1.1
sourcesrc
created_at2024-02-17 12:38:51.124623
updated_at2024-12-04 11:43:09.304061
descriptionDe/serialization functions for byte-unit crate.
homepage
repositoryhttps://github.com/alekseysidorov/byte-unit-serde
max_upload_size
id1143193
size18,798
Aleksey Sidorov (alekseysidorov)

documentation

README

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.

Commit count: 15

cargo fmt