pub struct ZeroCopyBuffer { /* private fields */ }Expand description
An immutable view over a region of bytes. Cloneable at O(1) — the
backing storage is an Arc<[u8]> so clones are refcount bumps.
Slicing returns another ZeroCopyBuffer that references the same
underlying allocation: no copies, no new allocations on the hot
path. When the last ZeroCopyBuffer referencing an allocation
drops, the storage returns to the BufferPool (if it came from
one) or is freed (if direct-allocated).
Implementations§
Source§impl ZeroCopyBuffer
impl ZeroCopyBuffer
Sourcepub fn from_bytes(bytes: impl Into<Vec<u8>>, kind: BufferKind) -> Self
pub fn from_bytes(bytes: impl Into<Vec<u8>>, kind: BufferKind) -> Self
Construct from an already-owned byte slice. Copies once into
the Arc — use ZeroCopyBuffer::from_arc to avoid that copy
when the caller already has an Arc<[u8]>.
Sourcepub fn from_arc(storage: Arc<[u8]>, kind: BufferKind) -> Self
pub fn from_arc(storage: Arc<[u8]>, kind: BufferKind) -> Self
Construct from an existing Arc<[u8]> without copying.
Sourcepub fn with_tenant(self, tenant_id: impl Into<Arc<str>>) -> Self
pub fn with_tenant(self, tenant_id: impl Into<Arc<str>>) -> Self
Tag the buffer with its owning tenant (for pool accounting).
pub fn is_empty(&self) -> bool
Sourcepub fn kind(&self) -> BufferKind
pub fn kind(&self) -> BufferKind
Content-kind tag.
pub fn tenant_id(&self) -> Option<&str>
Sourcepub fn retag(&self, kind: BufferKind) -> Self
pub fn retag(&self, kind: BufferKind) -> Self
Upgrade the content-kind tag (e.g. raw → jpeg after
format detection). Returns a new ZeroCopyBuffer that shares
the backing storage; the original view is untouched so other
holders see the old kind unchanged.
Sourcepub fn as_slice(&self) -> &[u8] ⓘ
pub fn as_slice(&self) -> &[u8] ⓘ
Borrow the visible byte range as a slice. Callers usually
reach for ZeroCopyBuffer::as_slice (alias) or feed this
straight to their consumer. Do not copy the slice on the
hot path — pass the ZeroCopyBuffer by reference instead.
Sourcepub fn slice(&self, range: Range<usize>) -> Self
pub fn slice(&self, range: Range<usize>) -> Self
Return a sub-view into this buffer. O(1) — no copy; the
returned buffer shares the same Arc.
Number of live views over the backing storage (Arc strong count). Useful for observability; do NOT use for flow control.
Trait Implementations§
Source§impl Clone for ZeroCopyBuffer
impl Clone for ZeroCopyBuffer
Source§fn clone(&self) -> ZeroCopyBuffer
fn clone(&self) -> ZeroCopyBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more