Skip to main content

ArenaView

Struct ArenaView 

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

Source

pub const fn len(&self) -> usize

Returns the number of bytes visible through this temporary view.

Source

pub const fn is_empty(&self) -> bool

Returns true when no bytes are visible through this view.

Source

pub const fn as_uninit_slice(&self) -> &[MaybeUninit<u8>]

Returns the remaining arena bytes as uninitialized storage.

Source

pub const fn as_slice(&self) -> &[MaybeUninit<u8>]

Returns the remaining arena bytes as uninitialized storage.

Source

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.

Source

pub const fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<u8>]

Returns the remaining arena bytes as mutable uninitialized storage.

Source

pub const fn as_slice_mut(&mut self) -> &mut [MaybeUninit<u8>]

Returns the remaining arena bytes as mutable uninitialized storage.

Source

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.

Source

pub fn init_with<F, E>(&mut self, f: F) -> Result<&mut [u8], E>
where F: FnOnce(&mut [u8]) -> Result<usize, 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().

Source

pub fn init_prefix_with<F, E>(self, f: F) -> Result<&'buf mut [u8], E>
where F: FnOnce(&mut [u8]) -> Result<usize, 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().

Source

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().

Source

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.

Auto Trait Implementations§

§

impl<'arena, 'buf> Freeze for ArenaView<'arena, 'buf>

§

impl<'arena, 'buf> RefUnwindSafe for ArenaView<'arena, 'buf>

§

impl<'arena, 'buf> !Send for ArenaView<'arena, 'buf>

§

impl<'arena, 'buf> !Sync for ArenaView<'arena, 'buf>

§

impl<'arena, 'buf> Unpin for ArenaView<'arena, 'buf>

§

impl<'arena, 'buf> UnsafeUnpin for ArenaView<'arena, 'buf>

§

impl<'arena, 'buf> UnwindSafe for ArenaView<'arena, 'buf>

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.