pub type Bytes = RawBytes<Compact>;Available on crate features
alloc or std only.Expand description
A memory-efficient byte buffer that aggressively inlines data to minimize heap usage.
This type alias uses the Compact strategy.
§When to use
Use Bytes (with Compact strategy) when:
- Memory footprint is critical
- You’re working with small, frequently-modified buffers
- Heap allocations should be minimized
- Conversions to
bytes::Bytesare infrequent
For applications that frequently convert to/from Bytes, consider shared::Bytes instead.
§Example
use smol_bytes::compact::Bytes;
use bytes::Buf;
let mut data = Bytes::from(vec![1u8; 100]);
assert!(data.is_heap());
// After advancing, automatically converts to inline
data.advance(70);
assert!(!data.is_heap()); // Saved memory!Aliased Type§
pub struct Bytes { /* private fields */ }