pub struct Storage<T> { /* private fields */ }Expand description
A typed parallel storage indexed by u32 slot indices.
Managed by IdAllocator — this storage does not
decide which slots are alive. It only tracks which slots have been initialized.
§Performance
set(): O(1) amortized (may grow the Vec).get(): O(1) — array index + initialized check.- Cache-friendly: contiguous memory, linear access patterns.
Implementations§
Source§impl<T> Storage<T>
impl<T> Storage<T>
Sourcepub fn set(&mut self, index: u32, value: T)
pub fn set(&mut self, index: u32, value: T)
Write a value at the given index. Grows if needed. Drops the old value if the slot was already initialized.
Sourcepub fn is_initialized(&self, index: u32) -> bool
pub fn is_initialized(&self, index: u32) -> bool
Check if a slot has been initialized.
Sourcepub fn get(&self, index: u32) -> Option<&T>
pub fn get(&self, index: u32) -> Option<&T>
Safe read — returns None if not initialized or out of bounds.
Sourcepub fn get_mut(&mut self, index: u32) -> Option<&mut T>
pub fn get_mut(&mut self, index: u32) -> Option<&mut T>
Safe mutable read — returns None if not initialized or out of bounds.
Sourcepub unsafe fn get_unchecked(&self, index: u32) -> &T
pub unsafe fn get_unchecked(&self, index: u32) -> &T
Unchecked read — caller must ensure the slot is initialized.
§Safety
The slot at index must have been initialized via set().
Sourcepub unsafe fn get_unchecked_mut(&mut self, index: u32) -> &mut T
pub unsafe fn get_unchecked_mut(&mut self, index: u32) -> &mut T
Unchecked mutable read — caller must ensure the slot is initialized.
§Safety
The slot at index must have been initialized via set().
Sourcepub fn take(&mut self, index: u32) -> Option<T>
pub fn take(&mut self, index: u32) -> Option<T>
Remove the value at the given index and return it.
Returns None if not initialized.
Sourcepub fn iter(&self) -> impl Iterator<Item = (u32, &T)> + '_
pub fn iter(&self) -> impl Iterator<Item = (u32, &T)> + '_
Iterate over all initialized (index, &value) pairs.
Sourcepub fn clear_slot(&mut self, index: u32)
pub fn clear_slot(&mut self, index: u32)
Mark a slot as uninitialized and drop its value. Safe to call on already-uninitialized slots (no-op).