pub struct Arena<K, T> { /* private fields */ }Expand description
A minimal generational arena (house rule: 40 boring lines beat a
dependency). Slots are reused; each reuse bumps the generation.
Insertion is checked (0056 AR13): a slot whose generation would wrap
is retired — never reused — so a stale key can never alias a new
occupant, and a full index space refuses instead of truncating
slots.len() onto a live slot.
Implementations§
Source§impl<K, T> Arena<K, T>
impl<K, T> Arena<K, T>
Sourcepub fn seed_with<U>(&self, f: impl FnMut(&T) -> U) -> ArenaSeed<U>
pub fn seed_with<U>(&self, f: impl FnMut(&T) -> U) -> ArenaSeed<U>
Capture the arena, mapping every live value through f.
Sourcepub fn from_seed(seed: ArenaSeed<T>) -> Result<Self, ArenaSeedError>
pub fn from_seed(seed: ArenaSeed<T>) -> Result<Self, ArenaSeedError>
Rebuild an arena. The free list must name only empty slots, each at most once; a seed that disagrees is rejected, never coerced into a plausible-but-wrong identity layout. Empty slots missing from the free list are retired identities, not corruption.
Source§impl<K, T> Arena<K, T>
impl<K, T> Arena<K, T>
Sourcepub fn try_insert(&mut self, value: T) -> Result<Id<K>, ArenaExhausted>
pub fn try_insert(&mut self, value: T) -> Result<Id<K>, ArenaExhausted>
Checked insertion: reuses a free slot only when its generation can advance without wrapping; retired (wrap-risk) slots are dropped from the free list for good. Fails only when no slot is reusable and the index space itself is full — the arena is left unchanged, so an in-flight operation keeps every existing document/edit.
Sourcepub fn insert_capacity(&self) -> u64
pub fn insert_capacity(&self) -> u64
How many more inserts this arena can serve: reusable free slots plus the remaining index space. Multi-document operations preflight against this instead of failing halfway through.
pub fn get_mut(&mut self, id: Id<K>) -> Option<&mut T>
Sourcepub fn remove(&mut self, id: Id<K>) -> Option<T>
pub fn remove(&mut self, id: Id<K>) -> Option<T>
Remove and return the value; stale ids get None.
pub fn iter(&self) -> impl Iterator<Item = (Id<K>, &T)>
Sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
Mutable values without copying keys or exposing vacant slots.