#buffers #zero-copy #io


Types and traits for working with bytes (bytes crate fork)

22 releases

0.1.21 Nov 10, 2023
0.1.19 Jan 23, 2023
0.1.18 Dec 13, 2022
0.1.16 Jul 7, 2022
0.1.4 Jun 27, 2021

#596 in Network programming

Download history 963/week @ 2023-08-16 784/week @ 2023-08-23 719/week @ 2023-08-30 957/week @ 2023-09-06 1003/week @ 2023-09-13 713/week @ 2023-09-20 805/week @ 2023-09-27 864/week @ 2023-10-04 767/week @ 2023-10-11 850/week @ 2023-10-18 957/week @ 2023-10-25 1317/week @ 2023-11-01 1368/week @ 2023-11-08 1196/week @ 2023-11-15 1497/week @ 2023-11-22 1141/week @ 2023-11-29

5,378 downloads per month
Used in 49 crates (15 directly)

MIT license



A utility library for working with bytes. This is fork of bytes crate (https://github.com/tokio-rs/bytes)




To use bytes, first add this to your Cargo.toml:

ntex-bytes = "0.1"

Next, add this to your crate:

use ntex_bytes::{Bytes, BytesMut, Buf, BufMut};

Serde support

Serde support is optional and disabled by default. To enable use the feature serde.

ntex-bytes = { version = "0.1", features = ["serde"] }


This project is licensed under the MIT license.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in ntex-bytes by you, shall be licensed as MIT, without any additional terms or conditions.


Provides abstractions for working with bytes.

This is fork of bytes crate

The ntex-bytes crate provides an efficient byte buffer structure (Bytes) and traits for working with buffer implementations (Buf, BufMut).


Bytes is an efficient container for storing and operating on contiguous slices of memory. It is intended for use primarily in networking code, but could have applications elsewhere as well.

Bytes values facilitate zero-copy network programming by allowing multiple Bytes objects to point to the same underlying memory. This is managed by using a reference count to track when the memory is no longer needed and can be freed.

A Bytes handle can be created directly from an existing byte store (such as &[u8] or Vec<u8>), but usually a BytesMut is used first and written to. For example:

use ntex_bytes::{BytesMut, BufMut};

let mut buf = BytesMut::with_capacity(1024);
buf.put(&b"hello world"[..]);

let a = buf.split();
assert_eq!(a, b"hello world\x04\xD2"[..]);

buf.put(&b"goodbye world"[..]);

let b = buf.split();
assert_eq!(b, b"goodbye world"[..]);

assert_eq!(buf.capacity(), 998);

In the above example, only a single buffer of 1024 is allocated. The handles a and b will share the underlying buffer and maintain indices tracking the view into the buffer represented by the handle.

See the struct docs for more details.


~13K SLoC