3 releases

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

#826 in Encoding

Download history 1213/week @ 2024-08-09 1226/week @ 2024-08-16 1130/week @ 2024-08-23 738/week @ 2024-08-30 1295/week @ 2024-09-06 842/week @ 2024-09-13 1021/week @ 2024-09-20 905/week @ 2024-09-27 1239/week @ 2024-10-04 1549/week @ 2024-10-11 2013/week @ 2024-10-18 1244/week @ 2024-10-25 1455/week @ 2024-11-01 875/week @ 2024-11-08 941/week @ 2024-11-15 824/week @ 2024-11-22

4,425 downloads per month
Used in 9 crates (5 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

~105–335KB