pub struct StagingBuffer<'arena, 'b> { /* private fields */ }Expand description
A staging buffer over the remaining bytes of a PrefixArena.
StagingBuffer lets callers append bytes into temporary arena-backed
storage, inspect the written prefix, and finally detach that written prefix
from the underlying arena.
Implementations§
Source§impl<'arena, 'b> StagingBuffer<'arena, 'b>where
'b: 'arena,
impl<'arena, 'b> StagingBuffer<'arena, 'b>where
'b: 'arena,
Sourcepub const fn new(arena: &'arena mut PrefixArena<'b>) -> Self
pub const fn new(arena: &'arena mut PrefixArena<'b>) -> Self
Creates a staging buffer over the remaining space of the given arena.
Sourcepub fn push_byte(&mut self, byte: u8) -> Result<(), StagingBufferError>
pub fn push_byte(&mut self, byte: u8) -> Result<(), StagingBufferError>
Appends one byte to the written prefix.
Returns Ok(()) on success and Err(()) if no capacity remains.
Sourcepub fn extend_from_slice(
&mut self,
slice: &[u8],
) -> Result<(), StagingBufferError>
pub fn extend_from_slice( &mut self, slice: &[u8], ) -> Result<(), StagingBufferError>
Appends the entire slice to the written prefix.
Returns Ok(()) on success and Err(()) if the full slice does not fit.
Sourcepub fn extend_from_slice_capped(&mut self, slice: &[u8]) -> usize
pub fn extend_from_slice_capped(&mut self, slice: &[u8]) -> usize
Appends as much of the slice as fits and returns the number of bytes written.
Sourcepub fn written_mut(&mut self) -> &mut [u8]
pub fn written_mut(&mut self) -> &mut [u8]
Returns the written prefix as a mutable slice.
Sourcepub const fn spare_capacity(&self) -> usize
pub const fn spare_capacity(&self) -> usize
Returns how many bytes can still be appended without overflowing.
Sourcepub fn into_written_slice(self) -> &'b mut [u8]
pub fn into_written_slice(self) -> &'b mut [u8]
Detaches the written prefix from the underlying arena.