pub struct SharedArena<T> { /* private fields */ }Expand description
Thread-safe typed arena allocator.
Concurrent allocation via &self. Wait-free reads returning &T
directly (no guards or locks). Same Idx<T> handles and
Checkpoint<T> semantics as Arena.
SharedArena<T> is Send + Sync when T: Send + Sync.
For single-thread usage with zero overhead, see Arena.
Implementations§
Sourcepub fn alloc(&self, value: T) -> Idx<T>
pub fn alloc(&self, value: T) -> Idx<T>
Allocates a value, returning its stable index.
Can be called concurrently from multiple threads (&self).
O(1).
§Panics
Panics if internal slot reservation fails (should not happen in normal usage).
Sourcepub fn get(&self, idx: Idx<T>) -> &T
pub fn get(&self, idx: Idx<T>) -> &T
Returns a reference to the value at idx.
Wait-free. Returns &T directly (no guard or lock).
§Panics
Panics if idx is out of bounds (stale after rollback/reset).
Sourcepub fn checkpoint(&self) -> Checkpoint<T>
pub fn checkpoint(&self) -> Checkpoint<T>
Saves the current allocation state.
Use with rollback to discard allocations
made after this point.
Sourcepub fn rollback(&mut self, cp: Checkpoint<T>)
pub fn rollback(&mut self, cp: Checkpoint<T>)
Rolls back to a previous checkpoint, dropping all values allocated after it.
O(k) where k = number of items dropped (destructors run).
§Panics
Panics if cp points beyond the current length.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Removes all items, running their destructors.
Retains allocated storage for reuse.
Sourcepub fn is_valid(&self, idx: Idx<T>) -> bool
pub fn is_valid(&self, idx: Idx<T>) -> bool
Returns true if idx points to a valid item in this arena.
Sourcepub fn try_get(&self, idx: Idx<T>) -> Option<&T>
pub fn try_get(&self, idx: Idx<T>) -> Option<&T>
Returns a reference to the value at idx, or None if the
index is out of bounds.
Sourcepub fn alloc_extend(&self, iter: impl IntoIterator<Item = T>) -> Option<Idx<T>>
pub fn alloc_extend(&self, iter: impl IntoIterator<Item = T>) -> Option<Idx<T>>
Allocates multiple values from an iterator, returning the index of the first allocated item.
Returns None if the iterator is empty.
O(n) where n = items yielded by the iterator.
Sourcepub fn iter(&self) -> SharedArenaIter<'_, T> ⓘ
pub fn iter(&self) -> SharedArenaIter<'_, T> ⓘ
Returns an iterator over all published items in allocation order.
Sourcepub fn iter_indexed(&self) -> SharedArenaIterIndexed<'_, T> ⓘ
pub fn iter_indexed(&self) -> SharedArenaIterIndexed<'_, T> ⓘ
Returns an iterator yielding (Idx<T>, &T) pairs in allocation order.
Trait Implementations§
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)