pub struct ArenaView<'arena, 'buf>where
'buf: 'arena,{ /* private fields */ }Expand description
A temporary view over the remaining bytes of a PrefixArena.
This is useful when code needs to fill an unknown-sized prefix of the remaining arena and then detach only the initialized portion.
Implementations§
Source§impl<'arena, 'buf> ArenaView<'arena, 'buf>
impl<'arena, 'buf> ArenaView<'arena, 'buf>
Sourcepub const fn len(&self) -> usize
pub const fn len(&self) -> usize
Returns the number of bytes visible through this temporary view.
Sourcepub const fn as_uninit_slice(&self) -> &[MaybeUninit<u8>]
pub const fn as_uninit_slice(&self) -> &[MaybeUninit<u8>]
Returns the remaining arena bytes as uninitialized storage.
Sourcepub const fn as_slice(&self) -> &[MaybeUninit<u8>]
pub const fn as_slice(&self) -> &[MaybeUninit<u8>]
Returns the remaining arena bytes as uninitialized storage.
Sourcepub const unsafe fn as_slice_unchecked(&self) -> &[u8]
pub const unsafe fn as_slice_unchecked(&self) -> &[u8]
Returns the remaining arena bytes as u8.
§Safety
Every returned byte must be initialized before it is read as u8.
Sourcepub const fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub const fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<u8>]
Returns the remaining arena bytes as mutable uninitialized storage.
Sourcepub const fn as_slice_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub const fn as_slice_mut(&mut self) -> &mut [MaybeUninit<u8>]
Returns the remaining arena bytes as mutable uninitialized storage.
Sourcepub const unsafe fn as_slice_mut_unchecked(&mut self) -> &mut [u8]
pub const unsafe fn as_slice_mut_unchecked(&mut self) -> &mut [u8]
Returns the remaining arena bytes as mutable u8.
§Safety
Every returned byte must be initialized before it is read as u8.
Sourcepub fn init_with<F, E>(&mut self, f: F) -> Result<&mut [u8], E>
pub fn init_with<F, E>(&mut self, f: F) -> Result<&mut [u8], E>
Lets f initialize a prefix of the temporary view and returns that prefix.
This method does not shrink the underlying arena.
§Panics
Panics if f returns a length greater than self.len().
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>
Lets f initialize a prefix of the temporary view and then detaches that
prefix from the underlying arena.
If f returns Err, the underlying 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 self.len().
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 underlying 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]where
'buf: 'arena,
pub unsafe fn take_prefix_unchecked(self, n: usize) -> &'buf mut [u8]where
'buf: 'arena,
Removes the first n bytes from the underlying 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.