Skip to main content

Bytes

Type Alias Bytes 

Source
pub type Bytes = RawBytes<Shared>;
Available on crate features alloc or std only.
Expand description

A space-efficient byte buffer that shares heap allocations with bytes::Bytes.

This type alias uses the Shared strategy.

§When to use

Use Bytes (with Shared strategy) when:

  • You frequently convert to/from bytes::Bytes
  • You want fast, zero-copy operations
  • Memory overhead is acceptable for performance gains

For memory-constrained applications, consider compact::Bytes instead.

§Example

use smol_bytes::shared::Bytes;

let data = Bytes::from_static(b"hello world");
assert_eq!(data.as_slice(), b"hello world");

// Efficient conversion to Bytes
let bytes: bytes::Bytes = data.into();

Aliased Type§

pub struct Bytes { /* private fields */ }