pub struct Store<T> { /* private fields */ }Expand description
Components of one type, addressed by entity slot.
Implementations§
Source§impl<T> Store<T>
impl<T> Store<T>
Sourcepub fn insert(&mut self, slot: u32, value: T) -> Option<T>
pub fn insert(&mut self, slot: u32, value: T) -> Option<T>
Store a component, returning the one it replaced.
Sourcepub fn remove(&mut self, slot: u32) -> Option<T>
pub fn remove(&mut self, slot: u32) -> Option<T>
Remove a component, returning it.
The last element is swapped into the hole, so this is constant
time and values stays contiguous — at the cost of dense losing
any order it had, which is the trade Store::iter pays for.
Sourcepub fn iter(&self) -> impl Iterator<Item = (u32, &T)> + '_
pub fn iter(&self) -> impl Iterator<Item = (u32, &T)> + '_
Every component, in ascending entity-slot order.
This is the order the engine promises, and it is why the store
exists in this shape. It walks sparse, so its cost is
proportional to the highest occupied slot rather than to the number
of components — a store scattered across a wide slot range pays for
the gaps. That is the measured cost of a defined order, and the
entity allocator reuses low slots first precisely to keep it small.
Sourcepub fn for_each_mut(&mut self, visit: impl FnMut(u32, &mut T))
pub fn for_each_mut(&mut self, visit: impl FnMut(u32, &mut T))
Every component in slot order, mutably.
Collects the visit order first, because handing out &mut while
borrowing sparse to decide the order is not something the borrow
checker will allow — and the honest fix is one allocation per
call, not unsafe.
Sourcepub fn iter_unordered(&self) -> impl Iterator<Item = &T> + '_
pub fn iter_unordered(&self) -> impl Iterator<Item = &T> + '_
The components in storage order, which is unspecified.
Offered because it is what a system that does not care about order
should use: it is a flat walk of a contiguous array, with none of
the gap-skipping Store::iter pays for. Any system whose result
depends on the order it sees is wrong to use this, and the name is
the warning.