pub struct PrefixArena<'buf> { /* private fields */ }Expand description
A bump-style arena over caller-provided byte storage.
PrefixArena hands out slices from the front of the remaining buffer and keeps
the rest available for later use. It only manages buffer boundaries; it does
not track which bytes are initialized.
Implementations§
Source§impl<'buf> PrefixArena<'buf>
impl<'buf> PrefixArena<'buf>
pub const fn new(arena: &'buf mut [u8]) -> Self
pub const fn from_uninit(arena: &'buf mut [MaybeUninit<u8>]) -> Self
Sourcepub const fn view<'arena>(&'arena mut self) -> ArenaView<'arena, 'buf>
pub const fn view<'arena>(&'arena mut self) -> ArenaView<'arena, 'buf>
Borrows the currently remaining arena space through a temporary view.
Sourcepub fn take_prefix(&self, n: usize) -> &'buf mut [MaybeUninit<u8>]
pub fn take_prefix(&self, n: usize) -> &'buf mut [MaybeUninit<u8>]
Removes the first n bytes from the remaining arena and returns them.
The returned slice is uninitialized storage. The caller must initialize it before reading from it.
§Panics
Panics if n > self.len().
Sourcepub unsafe fn take_prefix_unchecked(&self, n: usize) -> &'buf mut [u8]
pub unsafe fn take_prefix_unchecked(&self, n: usize) -> &'buf mut [u8]
Removes the first n bytes from the remaining arena and returns them as u8.
§Safety
The caller must ensure both of the following:
n <= self.len().- Every returned byte is initialized before it is read as
u8.
Sourcepub fn take_remaining(self) -> &'buf mut [MaybeUninit<u8>]
pub fn take_remaining(self) -> &'buf mut [MaybeUninit<u8>]
Returns all bytes that still remain in the arena and consumes self.
The returned slice is uninitialized storage. The caller must initialize it before reading from it.
Sourcepub fn init_prefix_with<F, E>(self, f: F) -> Result<&'buf mut [u8], E>
pub fn init_prefix_with<F, E>(self, f: F) -> Result<&'buf mut [u8], E>
Exposes the remaining arena as &mut [u8], lets f initialize a prefix,
and then detaches that initialized prefix from the arena.
If f returns Err, the arena remains unchanged.
§Safety
f must return the length of a prefix that it actually initialized.
§Panics
Panics if f returns a length greater than the currently remaining size.