https://github.com/nitrokey/serde-byte-array
https://github.com/nitrokey/serde-byte-array
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nitrokey/serde-byte-array
- Owner: Nitrokey
- License: apache-2.0
- Created: 2023-02-23T15:44:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-05T08:03:32.000Z (almost 3 years ago)
- Last Synced: 2025-08-09T22:43:20.588Z (11 months ago)
- Language: Rust
- Size: 23.4 KB
- Stars: 6
- Watchers: 7
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# 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`.
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
```rust
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.