Crates.io | serde-byte-array |
lib.rs | serde-byte-array |
version | 0.1.2 |
source | src |
created_at | 2023-02-24 09:45:41.320013 |
updated_at | 2023-02-27 10:58:47.583283 |
description | Optimized handling of `[u8; N]` for Serde |
homepage | |
repository | https://github.com/nitrokey/serde-byte-array |
max_upload_size | |
id | 793441 |
size | 33,559 |
Wrapper types to enable optimized handling of [u8; N]
Without specialization, Rust forces Serde to treat [u8; N]
just like any
other arary In reality this particular array can often be serialized and
deserialized in a more efficient, compact representation in many formats.
When working with such a format, you can opt into specialized handling of
[u8; N]
by wrapping it in serde_byte_array::ByteArray<N>
.
Additionally this crate supports the Serde with
attribute to enable efficient
handling of [u8; N]
and &[u8; N]
in structs without needing a wrapper type.
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
struct Efficient<'a> {
#[serde(with = "serde_byte_array")]
bytes: [u8; 3],
#[serde(with = "serde_byte_array", borrow)]
bytes_ref: &'a [u8; 3],
}