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>
impl<'buf> Arena<'buf>
Sourcepub fn with_buffer(buf: &'buf mut [u8]) -> Self
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.
Sourcepub fn bytes_used(&self) -> usize
pub fn bytes_used(&self) -> usize
Returns the number of bytes in use, not counting alignment padding.
Sourcepub fn bytes_reserved(&self) -> usize
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.
Sourcepub fn set_capacity_limit(&self, max_reserved_bytes: usize)
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.
Trait Implementations§
Source§impl Debug for Arena<'_>
Prints bytes_used and bytes_reserved.
impl Debug for Arena<'_>
Prints bytes_used and bytes_reserved.