| 1 | # Bytes |
| 2 | |
| 3 | A utility library for working with bytes. |
| 4 | |
| 5 | [![Crates.io][crates-badge]][crates-url] |
| 6 | [![Build Status][ci-badge]][ci-url] |
| 7 | |
| 8 | [crates-badge]: https://img.shields.io/crates/v/bytes.svg |
| 9 | [crates-url]: https://crates.io/crates/bytes |
| 10 | [ci-badge]: https://github.com/tokio-rs/bytes/workflows/CI/badge.svg |
| 11 | [ci-url]: https://github.com/tokio-rs/bytes/actions |
| 12 | |
| 13 | [Documentation](https://docs.rs/bytes) |
| 14 | |
| 15 | ## Usage |
| 16 | |
| 17 | To use `bytes`, first add this to your `Cargo.toml`: |
| 18 | |
| 19 | ```toml |
| 20 | [dependencies] |
| 21 | bytes = "1" |
| 22 | ``` |
| 23 | |
| 24 | Next, add this to your crate: |
| 25 | |
| 26 | ```rust |
| 27 | use bytes::{Bytes, BytesMut, Buf, BufMut}; |
| 28 | ``` |
| 29 | |
| 30 | ## no_std support |
| 31 | |
| 32 | To use `bytes` with no_std environment, disable the (enabled by default) `std` feature. |
| 33 | |
| 34 | ```toml |
| 35 | [dependencies] |
| 36 | bytes = { version = "1", default-features = false } |
| 37 | ``` |
| 38 | |
| 39 | To use `bytes` with no_std environment without atomic CAS, such as thumbv6m, you also need to enable |
| 40 | the `extra-platforms` feature. See the [documentation for the `portable-atomic` |
| 41 | crate](https://docs.rs/portable-atomic) for more information. |
| 42 | |
| 43 | The MSRV when `extra-platforms` feature is enabled depends on the MSRV of `portable-atomic`. |
| 44 | |
| 45 | ## Serde support |
| 46 | |
| 47 | Serde support is optional and disabled by default. To enable use the feature `serde`. |
| 48 | |
| 49 | ```toml |
| 50 | [dependencies] |
| 51 | bytes = { version = "1", features = ["serde"] } |
| 52 | ``` |
| 53 | |
| 54 | The MSRV when `serde` feature is enabled depends on the MSRV of `serde`. |
| 55 | |
| 56 | ## Building documentation |
| 57 | |
| 58 | When building the `bytes` documentation the `docsrs` option should be used, otherwise |
| 59 | feature gates will not be shown. This requires a nightly toolchain: |
| 60 | |
| 61 | ``` |
| 62 | RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc |
| 63 | ``` |
| 64 | |
| 65 | ## License |
| 66 | |
| 67 | This project is licensed under the [MIT license](LICENSE). |
| 68 | |
| 69 | ### Contribution |
| 70 | |
| 71 | Unless you explicitly state otherwise, any contribution intentionally submitted |
| 72 | for inclusion in `bytes` by you, shall be licensed as MIT, without any additional |
| 73 | terms or conditions. |