pub trait ComponentStorageTrait {
// Required methods
fn remove_entity(&mut self, entity: Entity);
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
}Expand description
A type-erased interface over concrete ComponentStorage<T> implementations.
Enables the World to store heterogeneous component storages behind a single
trait object and perform operations such as removing an entity’s component
without knowing the concrete T at compile time.
§Safety
- Downcasting is only exposed via
as_any/as_any_mutand is guarded by externalTypeIdchecks inWorldbefore downcast is attempted. remove_entitymust maintain dense storage invariants of the underlying storage (e.g., swap-remove updates index maps) when implemented.
Required Methods§
Sourcefn remove_entity(&mut self, entity: Entity)
fn remove_entity(&mut self, entity: Entity)
Removes the component associated with entity from this storage, if present.
§Parameters
entity: The entity whose component should be removed from this storage.
§Effects
- If a component exists for
entity, it is removed. Implementations typically use swap-remove to keep storage dense and update internal mappings accordingly.
Sourcefn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
Returns a type-erased immutable view of this storage for downcasting.
§Returns
&dyn Any: A reference that can be downcast usingAny::downcast_refto access the concreteComponentStorage<T>when the caller knowsT.
§Safety
- Callers must only downcast to the correct type, typically ensured via
TypeIdchecks performed byWorldhelpers.
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns a type-erased mutable view of this storage for downcasting.
§Returns
&mut dyn Any: A mutable reference that can be downcast usingAny::downcast_mutto access the concreteComponentStorage<T>.
§Safety
- Callers must ensure the downcast target type matches the actual storage type.
The
Worldensures correctness viaTypeIdchecks before downcasting.