• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H03-May-2022-772539

tests/H03-May-2022-11192

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D04-May-201930 43

.travis.ymlH A D04-May-2019307 2016

Cargo.tomlH A D01-Jan-19701.2 KiB4338

Cargo.toml.orig-cargoH A D07-Aug-2019722 2924

LICENSE-APACHEH A D04-May-201910.6 KiB202169

LICENSE-MITH A D04-May-20191 KiB2622

README.mdH A D04-May-20191.6 KiB5539

README.md

1# serde\_bytes [![Build Status](https://api.travis-ci.org/serde-rs/bytes.svg?branch=master)](https://travis-ci.org/serde-rs/bytes) [![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