pub struct ByteArena { /* private fields */ }Expand description
Append-only byte store addressed by u32 offset. data.len() is the
(zero-filled) capacity; cursor is the live high-water mark — bytes
[0, cursor) are the appended payloads.
Implementations§
Source§impl ByteArena
impl ByteArena
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Empty arena pre-grown to capacity so the first appends don’t
re-grow.
Sourcepub fn append(&mut self, bytes: &[u8]) -> u32
pub fn append(&mut self, bytes: &[u8]) -> u32
Append bytes, returning the offset they were written at. Grows
the backing power-of-two when the bump would overflow capacity.
§Panics
Panics if the resulting high-water mark exceeds u32::MAX — the
address width of the returned offset. Callers with a bounded
window (in-flight bytes ≤ congestion window) never reach this.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reclaim everything: the next append starts at offset 0 again. The
backing allocation is retained for reuse. Sound only when no live
(offset, len) reference into the arena outlives the reset.
Sourcepub fn bytes_used(&self) -> usize
pub fn bytes_used(&self) -> usize
Live bytes appended since the last reset.