Struct fixed_typed_arena::arena::Arena
source · pub struct Arena<T, Options: ArenaOptions<T> = Options>(/* private fields */);
Expand description
An arena that allocates items of type T
in non-amortized O(1) (constant)
time.
The arena allocates fixed-size chunks of memory, each able to hold up to
Options::ChunkSize
items. All items are allocated on the heap.
Panics
The arena may panic when created or used if mem::size_of::<T>()
times Options::ChunkSize
is greater than usize::MAX
.
Implementations§
source§impl<T, Options: ArenaOptions<T>> Arena<T, Options>
impl<T, Options: ArenaOptions<T>> Arena<T, Options>
sourcepub fn alloc(&self, value: T) -> &mut Twhere
Options: ArenaOptions<T, Mutable = Bool<true>>,
pub fn alloc(&self, value: T) -> &mut Twhere Options: ArenaOptions<T, Mutable = Bool<true>>,
Allocates a new item in the arena and initializes it with value
.
Returns a reference to the allocated item.
This method calls handle_alloc_error
if memory allocation fails;
for a version that returns None
instead, see Self::try_alloc
.
sourcepub fn try_alloc(&self, value: T) -> Option<&mut T>where
Options: ArenaOptions<T, Mutable = Bool<true>>,
pub fn try_alloc(&self, value: T) -> Option<&mut T>where Options: ArenaOptions<T, Mutable = Bool<true>>,
Like Self::alloc
, but returns None
if memory allocation fails.
Allocates a new item in the arena and initializes it with value
.
Returns a shared/immutable reference to the allocated item.
This method calls handle_alloc_error
if memory allocation fails;
for a version that returns None
instead, see Self::try_alloc
.
Like Self::alloc_shared
, but returns None
if memory allocation
fails.
sourcepub fn iter(&self) -> Iter<'_, T, Options> ⓘwhere
Options: ArenaOptions<T, Mutable = Bool<false>>,
pub fn iter(&self) -> Iter<'_, T, Options> ⓘwhere Options: ArenaOptions<T, Mutable = Bool<false>>,
Returns an iterator over the items in this arena.
sourcepub unsafe fn iter_unchecked(&self) -> Iter<'_, T, Options> ⓘ
pub unsafe fn iter_unchecked(&self) -> Iter<'_, T, Options> ⓘ
source§impl<T, Options> Arena<T, Options>where
Options: ArenaOptions<T, SupportsPositions = Bool<true>>,
impl<T, Options> Arena<T, Options>where Options: ArenaOptions<T, SupportsPositions = Bool<true>>,
sourcepub fn iter_at(&self, position: &Position) -> Iter<'_, T, Options> ⓘwhere
Options: ArenaOptions<T, Mutable = Bool<false>>,
pub fn iter_at(&self, position: &Position) -> Iter<'_, T, Options> ⓘwhere Options: ArenaOptions<T, Mutable = Bool<false>>,
Returns an iterator starting at the specified position.
Panics
May panic if position
does not refer to a position in this arena.
sourcepub unsafe fn iter_at_unchecked(
&self,
position: &Position
) -> Iter<'_, T, Options> ⓘ
pub unsafe fn iter_at_unchecked( &self, position: &Position ) -> Iter<'_, T, Options> ⓘ
Returns an iterator starting at the specified position.
Panics
May panic if position
does not refer to a position in this arena.
Safety
Same requirements as Self::iter_unchecked
.