Skip to main content

StagingBuffer

Struct StagingBuffer 

Source
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,

Source

pub const fn new(arena: &'arena mut PrefixArena<'b>) -> Self

Creates a staging buffer over the remaining space of the given arena.

Source

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.

Source

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.

Source

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.

Source

pub fn written(&self) -> &[u8]

Returns the written prefix as an immutable slice.

Source

pub fn written_mut(&mut self) -> &mut [u8]

Returns the written prefix as a mutable slice.

Source

pub const fn len(&self) -> usize

Returns the number of bytes currently stored in the buffer.

Source

pub const fn is_empty(&self) -> bool

Returns true when no bytes have been written.

Source

pub const fn capacity(&self) -> usize

Returns the total capacity of the buffer.

Source

pub const fn spare_capacity(&self) -> usize

Returns how many bytes can still be appended without overflowing.

Source

pub fn clear(&mut self)

Marks the buffer as empty without modifying the underlying bytes.

Source

pub fn into_written_slice(self) -> &'b mut [u8]

Detaches the written prefix from the underlying arena.

Auto Trait Implementations§

§

impl<'arena, 'b> Freeze for StagingBuffer<'arena, 'b>

§

impl<'arena, 'b> RefUnwindSafe for StagingBuffer<'arena, 'b>

§

impl<'arena, 'b> !Send for StagingBuffer<'arena, 'b>

§

impl<'arena, 'b> !Sync for StagingBuffer<'arena, 'b>

§

impl<'arena, 'b> Unpin for StagingBuffer<'arena, 'b>

§

impl<'arena, 'b> UnsafeUnpin for StagingBuffer<'arena, 'b>

§

impl<'arena, 'b> UnwindSafe for StagingBuffer<'arena, 'b>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.