Trait ComponentStorageTrait

Source
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_mut and is guarded by external TypeId checks in World before downcast is attempted.
  • remove_entity must maintain dense storage invariants of the underlying storage (e.g., swap-remove updates index maps) when implemented.

Required Methods§

Source

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.
Source

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 using Any::downcast_ref to access the concrete ComponentStorage<T> when the caller knows T.
§Safety
  • Callers must only downcast to the correct type, typically ensured via TypeId checks performed by World helpers.
Source

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 using Any::downcast_mut to access the concrete ComponentStorage<T>.
§Safety
  • Callers must ensure the downcast target type matches the actual storage type. The World ensures correctness via TypeId checks before downcasting.

Implementors§