Skip to content

Nitrokey/serde-byte-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 array. 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.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages