Skip to main content

DropArena

Struct DropArena 

Source
pub struct DropArena<T> { /* private fields */ }
Expand description

Typed drop-honouring arena. See the module-level docs.

Implementations§

Source§

impl<T> DropArena<T>

Source

pub fn new() -> Self

Creates an empty arena. The first allocation triggers the allocation of an initial chunk holding 16 T slots.

Source

pub fn with_chunk_capacity(chunk_capacity: usize) -> Self

Creates an empty arena whose chunks each hold chunk_capacity T slots.

A chunk_capacity of zero is silently clamped to 1.

§Examples
use arena_lib::DropArena;

// Tightly-sized chunks — every alloc beyond the 4th opens a new chunk.
let arena = DropArena::<u32>::with_chunk_capacity(4);
for i in 0..4 {
    let _ = arena.alloc(i);
}
assert_eq!(arena.chunk_count(), 1);
let _ = arena.alloc(99);
assert_eq!(arena.chunk_count(), 2);
Source

pub fn len(&self) -> usize

Total number of T values currently held across every chunk.

Source

pub fn is_empty(&self) -> bool

Returns true when the arena holds no values.

Source

pub fn chunk_count(&self) -> usize

Number of chunks currently held.

Source

pub fn alloc(&self, value: T) -> &mut T

Allocates value and returns a unique reference to it.

The value is moved into a chunk; its destructor will run when the arena is dropped. Panics only if the global allocator itself fails.

§Examples
use arena_lib::DropArena;

let arena = DropArena::<String>::new();
let s = arena.alloc(String::from("owned"));
assert_eq!(s.as_str(), "owned");

Trait Implementations§

Source§

impl<T: Debug> Debug for DropArena<T>

Source§

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

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

impl<T> Default for DropArena<T>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<T> !Freeze for DropArena<T>

§

impl<T> !RefUnwindSafe for DropArena<T>

§

impl<T> Send for DropArena<T>
where T: Send,

§

impl<T> !Sync for DropArena<T>

§

impl<T> Unpin for DropArena<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DropArena<T>

§

impl<T> UnwindSafe for DropArena<T>
where T: UnwindSafe,

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.