pub struct TypedArenaGen<T, RM: RefMutability> { /* private fields */ }
Expand description

An arena that can hold objects of only one type. RM determines whether the references returned from allocation are mutable and whether iteration requires a mutable reference; either mutating returned references or iterating via immutable reference are possible, but not both.

Implementations§

source§

impl<T, RM: RefMutability> TypedArenaGen<T, RM>

source

pub fn new() -> Self

Creates a new, empty arena

source

pub fn alloc(&self, object: T) -> RM::Ref<'_, T>

Allocates an object in the TypedArena, returning a reference to it.

If the type parameter RM is Shared we return a shared reference. If RM is Mutable we return a mutable reference.

source

pub fn alloc_from_iter_reg( &self, iter: impl IntoIterator<Item = T> ) -> RM::SliceRef<'_, T>

Allocates multiple objects in a contiguous slice, returning a reference to the slice.

If the type parameter RM is Shared we return a shared reference. If RM is Mutable we return a mutable reference.

This collects into a SmallVec and then allocates by copying from it. Use alloc_from_iter if possible because it’s more efficient, copying directly without the intermediate collecting step. This default could be made more efficient, like crate::DroplessArena::alloc_from_iter, but it’s not hot enough to bother.

source

pub fn alloc_from_iter_fast( &self, iter: impl IterWithFastAlloc<T> ) -> RM::SliceRef<'_, T>

Allocates multiple objects in a contiguous slice, returning a reference to the slice.

If the type parameter RM is Shared we return a shared reference. If RM is Mutable we return a mutable reference.

This is equivalent semantics to Self::alloc_from_iter_reg except it’s faster, whereas Self::alloc_from_iter_reg permits more types.

source

pub fn len(&self) -> usize

Number of allocated elements in the arena.

source

pub fn is_empty(&self) -> bool

Does the arena have any allocated elements?

source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Iterates all allocated elements in the arena behind a mutable reference.

source

pub fn ptr_iter(&self) -> PtrIter<'_, T>

Iterates pointers to all allocated elements in the arena behind a shared reference. This is allows since we can have pointers even to mutably borrowed elements.

source

pub fn clear(&mut self)

Clears the arena, dropping all elements, but doesn’t free up its memory.

This means we can insert new elements without having to reallocate, until we reach the old capacity or allocate a slice too large to fit in an existing region.

source

pub fn retain(&mut self, predicate: impl FnMut(&mut T) -> bool)

Removes some elements from this arena, and coalesces the rest so that we don’t have gaps.

Pointers to regions in the memory may be invalidated as elements get rearranged. This function is behind a mutable reference, which ensures that there are no references to rearranged elements, but if there are any raw pointers they can no longer be dereferenced without UB.

source

pub fn convert<RM2: RefMutability>(self) -> TypedArenaGen<T, RM2>

Return self but with a different RefMutability.

With a mutable reference, we can convert between mutable and immutable variants, since there are no live allocated references.

source

pub fn into_vec(self) -> Vec<T>

Destroys this arena and collects all elements into a vector.

source

pub unsafe fn alloc_raw_slice(&self, len: usize) -> *mut T

Allocate a contiguous slice of data and return a pointer to the start of the slice. The slice is uninitialized (why we return a pointer), and you must initialize it before calling other arena methods or dropping the arena, or you will cause UB.

Safety

You must initialize the slice before calling other arena methods or dropping the arena. If iterating, you must initialize the slice before advancing the iterator.

source§

impl<T> TypedArenaGen<T, Shared>

source

pub fn iter(&self) -> Iter<'_, T>

Iterates all allocated elements in the arena behind a shared reference.

The iterator can handle new objects being allocated. If you allocate new objects they will be added to the end. If the iterator has already ended and you allocate new objects, it will suddenly have more elements; if you don’t want that behavior use fuse.

Trait Implementations§

source§

impl<T, RM: RefMutability> Default for TypedArenaGen<T, RM>

source§

fn default() -> Self

Creates a new, empty arena

source§

impl<T, RM: RefMutability> Drop for TypedArenaGen<T, RM>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, T> IntoIterator for &'a TypedArenaGen<T, Shared>

§

type Item = &'a T

The type of the elements being iterated over.
§

type IntoIter = IterGen<'a, T, Shared>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, T, RM: RefMutability> IntoIterator for &'a mut TypedArenaGen<T, RM>

§

type Item = &'a mut T

The type of the elements being iterated over.
§

type IntoIter = IterGen<'a, T, Mutable>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T: Send, RM: RefMutability> Send for TypedArenaGen<T, RM>

Auto Trait Implementations§

§

impl<T, RM> !RefUnwindSafe for TypedArenaGen<T, RM>

§

impl<T, RM> !Sync for TypedArenaGen<T, RM>

§

impl<T, RM> Unpin for TypedArenaGen<T, RM>where RM: Unpin, T: Unpin,

§

impl<T, RM> UnwindSafe for TypedArenaGen<T, RM>where RM: UnwindSafe, T: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.