#serde

no-std serde-byte-array

Optimized handling of [u8; N] for Serde

3 releases

0.1.2 Feb 27, 2023
0.1.1 Feb 24, 2023
0.1.0 Feb 24, 2023

#326 in Encoding

Download history 396/week @ 2023-06-13 521/week @ 2023-06-20 340/week @ 2023-06-27 388/week @ 2023-07-04 502/week @ 2023-07-11 495/week @ 2023-07-18 479/week @ 2023-07-25 587/week @ 2023-08-01 600/week @ 2023-08-08 798/week @ 2023-08-15 805/week @ 2023-08-22 732/week @ 2023-08-29 1182/week @ 2023-09-05 914/week @ 2023-09-12 900/week @ 2023-09-19 874/week @ 2023-09-26

3,987 downloads per month
Used in 5 crates (3 directly)

MIT/Apache

18KB
412 lines

serde_byte_array

Wrapper types to enable optimized handling of [u8; N]

Explanation

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.

Example

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],
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~115–355KB