• Home
Name Date Size #Lines LOC

..--

src/04-Jul-2025-1,272922

tests/04-Jul-2025-241205

.android-checksum.jsonD04-Jul-20251.5 KiB11

.cargo-checksum.jsonD04-Jul-20251.1 KiB11

Android.bpD04-Jul-2025942 3733

Cargo.tomlD04-Jul-20251.9 KiB8472

LICENSED04-Jul-20259.5 KiB177150

LICENSE-APACHED04-Jul-20259.5 KiB177150

METADATAD04-Jul-2025411 1817

MODULE_LICENSE_APACHE2D04-Jul-20250

README.mdD04-Jul-20251.7 KiB5539

cargo_embargo.jsonD04-Jul-202529 33

README.md

1# serde\_bytes [![Build Status](https://img.shields.io/github/actions/workflow/status/serde-rs/bytes/ci.yml?branch=master)](https://github.com/serde-rs/bytes/actions?query=branch%3Amaster) [![Latest Version](https://img.shields.io/crates/v/serde_bytes.svg)](https://crates.io/crates/serde_bytes)
2
3Wrapper types to enable optimized handling of `&[u8]` and `Vec<u8>`.
4
5```toml
6[dependencies]
7serde_bytes = "0.11"
8```
9
10## Explanation
11
12Without specialization, Rust forces Serde to treat `&[u8]` just like any
13other slice and `Vec<u8>` just like any other vector. In reality this
14particular slice and vector can often be serialized and deserialized in a
15more efficient, compact representation in many formats.
16
17When working with such a format, you can opt into specialized handling of
18`&[u8]` by wrapping it in `serde_bytes::Bytes` and `Vec<u8>` by wrapping it
19in `serde_bytes::ByteBuf`.
20
21Additionally this crate supports the Serde `with` attribute to enable efficient
22handling of `&[u8]` and `Vec<u8>` in structs without needing a wrapper type.
23
24## Example
25
26```rust
27use serde::{Deserialize, Serialize};
28
29#[derive(Deserialize, Serialize)]
30struct Efficient<'a> {
31    #[serde(with = "serde_bytes")]
32    bytes: &'a [u8],
33
34    #[serde(with = "serde_bytes")]
35    byte_buf: Vec<u8>,
36}
37```
38
39<br>
40
41#### License
42
43<sup>
44Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
452.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
46</sup>
47
48<br>
49
50<sub>
51Unless you explicitly state otherwise, any contribution intentionally submitted
52for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
53be dual licensed as above, without any additional terms or conditions.
54</sub>
55