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 moreAuto Trait Implementations§
impl Freeze for ZeroCopyBuffer
impl RefUnwindSafe for ZeroCopyBuffer
impl Send for ZeroCopyBuffer
impl Sync for ZeroCopyBuffer
impl Unpin for ZeroCopyBuffer
impl UnsafeUnpin for ZeroCopyBuffer
impl UnwindSafe for ZeroCopyBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more