Skip to main content

SystemContextExt

Trait SystemContextExt 

Source
pub trait SystemContextExt {
    // Required methods
    fn get<T: Component>(&self, entity: EntityId) -> Option<&T>;
    fn get_mut<T: Component>(&mut self, entity: EntityId) -> Option<&mut T>;
    fn set<T: Component>(&mut self, entity: EntityId, component: T);
    fn query<T: Component>(&self) -> Vec<EntityId> ;
}
Expand description

Typed convenience methods on SystemContext.

Implemented for dyn SystemContext so callers can write ctx.get::<Position>(id) instead of raw get_component + downcast.

Required Methods§

Source

fn get<T: Component>(&self, entity: EntityId) -> Option<&T>

Returns a typed component reference.

Source

fn get_mut<T: Component>(&mut self, entity: EntityId) -> Option<&mut T>

Returns a typed mutable component reference.

Source

fn set<T: Component>(&mut self, entity: EntityId, component: T)

Sets a typed component value for an entity.

Source

fn query<T: Component>(&self) -> Vec<EntityId>

Returns all entity IDs that have a component of type T.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§