API Reference

bytes

Utilities for working with byte buffers in Rust, providing efficient mutable and immutable types.

Official Documentation ↗
CompatibilityThis documentation covers version v1.6. Check the official docs for the latest API surface.

Installation

cargocargo add bytes

Methods

bytes offers Bytes, BytesMut, and the Buf and BufMut traits for zero-copy network code.

Key Features

  • Cheap cloning of Bytes via refcounting
  • Ergonomic read and write via Buf traits
  • Zero-copy slicing and splitting

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

API reference evidence

Fetched from official sources on 2026-11-08T09:38:08.940Z via WebFetch https://docs.rs/bytes/latest/bytes/struct.Bytes.html; WebFetch https://docs.rs/bytes/latest/bytes/struct.BytesMut.html; WebFetch https://docs.rs/bytes/latest/bytes/trait.Buf.html.

FAQ

When should I use Bytes versus Vec<u8>?
Use Bytes for cheap cloning and slicing in network code; use Vec when you need to mutate in place extensively.
Is cloning Bytes expensive?
No. Cloning increments a reference count, so it is far cheaper than copying the underlying data.
What do the Buf traits provide?
They give uniform read and write operations over buffers, so protocol code can work generically over different backends.