Struct rustc_arena_modified::typed_arena::TypedArenaGen
source · 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>
impl<T, RM: RefMutability> TypedArenaGen<T, RM>
sourcepub fn alloc_from_iter_reg(
&self,
iter: impl IntoIterator<Item = T>
) -> RM::SliceRef<'_, T>
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.
sourcepub fn alloc_from_iter_fast(
&self,
iter: impl IterWithFastAlloc<T>
) -> RM::SliceRef<'_, T>
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.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Iterates all allocated elements in the arena behind a mutable reference.
sourcepub fn ptr_iter(&self) -> PtrIter<'_, T> ⓘ
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.
sourcepub fn clear(&mut self)
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.
sourcepub fn retain(&mut self, predicate: impl FnMut(&mut T) -> bool)
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.
sourcepub fn convert<RM2: RefMutability>(self) -> TypedArenaGen<T, RM2>
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.
sourcepub unsafe fn alloc_raw_slice(&self, len: usize) -> *mut T
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.
sourcepub fn iter(&self) -> Iter<'_, T>
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
.