Skip to main content

Arena

Struct Arena 

Source
pub struct Arena<'buf> { /* private fields */ }
Expand description

The memory that arena decoders store messages in.

It hands out memory by moving a pointer forward. Dropping the arena frees all of it at once, and reset makes all of it available again. 'buf is the lifetime of the buffer given to with_buffer. Arena::new returns an Arena<'static>.

An arena is Send but not Sync. It can move to another thread when nothing borrows it, and an async task that holds an arena and the messages decoded into it can run on a multi-threaded executor.

Implementations§

Source§

impl<'buf> Arena<'buf>

Source

pub fn with_buffer(buf: &'buf mut [u8]) -> Self

Creates an arena that allocates from buf first.

With the alloc feature, the arena grows on the heap once buf is full. Without it, this is the only constructor, and allocation fails once buf is full. A buf of 16 bytes or less is ignored.

Source

pub fn bytes_used(&self) -> usize

Returns the number of bytes in use, not counting alignment padding.

Source

pub fn bytes_reserved(&self) -> usize

Returns the number of bytes the arena holds, in use or not, including a buffer given to with_buffer.

Source

pub fn set_capacity_limit(&self, max_reserved_bytes: usize)

Limits bytes_reserved, so untrusted input cannot make the arena grow without bound.

Growing past max_reserved_bytes fails, and the decode returns ErrorKind::ArenaExhausted. There is no limit by default. Without the alloc feature the arena never grows, so the limit has no effect.

Source

pub fn reset(&mut self)

Makes all of the arena’s memory available again.

The arena keeps the memory it holds and reuses it. Repeating the same decode allocates nothing, but a decode with larger values can still allocate.

Source§

impl Arena<'static>

Source

pub fn new() -> Arena<'static>

Available on crate feature alloc only.

Creates an empty arena that grows on the heap.

Trait Implementations§

Source§

impl Debug for Arena<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Arena<'static>

Available on crate feature alloc only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for Arena<'_>

Available on crate feature alloc only.
Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for Arena<'_>

Auto Trait Implementations§

§

impl<'buf> !Freeze for Arena<'buf>

§

impl<'buf> !RefUnwindSafe for Arena<'buf>

§

impl<'buf> !Sync for Arena<'buf>

§

impl<'buf> !UnwindSafe for Arena<'buf>

§

impl<'buf> Forget for Arena<'buf>

§

impl<'buf> Move for Arena<'buf>

§

impl<'buf> Unpin for Arena<'buf>

§

impl<'buf> UnsafeUnpin for 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.