pub trait FetchComponents {
type Item<'a>;
type ReadOnly: FetchComponents;
type Fetch<'a>;
type State: Send + Sync + Sized;
// Required methods
fn init_state(_world: &mut World, _meta: &mut SystemMeta) -> Self::State;
fn init_fetch<'w>(
world: &'w World,
state: &'w Self::State,
index: ArchetypeIndex,
tick: Tick,
last_run: Tick,
) -> Self::Fetch<'w>;
fn init_fetch_opt<'w>(
world: &'w World,
state: &'w Self::State,
index: ArchetypeIndex,
tick: Tick,
last_run: Tick,
) -> Option<Self::Fetch<'w>>;
fn fetch<'w>(fetch: &Self::Fetch<'w>, row: Row, e: Entity) -> Self::Item<'w>;
}Required Associated Types§
Sourcetype Item<'a>
type Item<'a>
The item returned by this FetchComponents
Sourcetype ReadOnly: FetchComponents
type ReadOnly: FetchComponents
ReadOnly
Sourcetype Fetch<'a>
type Fetch<'a>
Per archetype/table state used by this FetchComponents to fetch Self::Item
Sourcetype State: Send + Sync + Sized
type State: Send + Sync + Sized
State used to construct a Self::Fetch. This will be cached inside QueryState,
so it is best to move as much data / computation here as possible to reduce the cost of
constructing Self::Fetch.
Required Methods§
Sourcefn init_state(_world: &mut World, _meta: &mut SystemMeta) -> Self::State
fn init_state(_world: &mut World, _meta: &mut SystemMeta) -> Self::State
initializes ReadWrite for this FetchComponents type.
Sourcefn init_fetch<'w>(
world: &'w World,
state: &'w Self::State,
index: ArchetypeIndex,
tick: Tick,
last_run: Tick,
) -> Self::Fetch<'w>
fn init_fetch<'w>( world: &'w World, state: &'w Self::State, index: ArchetypeIndex, tick: Tick, last_run: Tick, ) -> Self::Fetch<'w>
Creates a new instance of this fetch.
§Safety
worldmust have permission to access any of the components specified inSelf::update_archetype_component_access.statemust have been initialized (via [FetchComponents::init_statee]) using the sameworldpassed in to this function.
fn init_fetch_opt<'w>( world: &'w World, state: &'w Self::State, index: ArchetypeIndex, tick: Tick, last_run: Tick, ) -> Option<Self::Fetch<'w>>
Sourcefn fetch<'w>(fetch: &Self::Fetch<'w>, row: Row, e: Entity) -> Self::Item<'w>
fn fetch<'w>(fetch: &Self::Fetch<'w>, row: Row, e: Entity) -> Self::Item<'w>
Fetch Self::Item for either the given entity in the current [Table],
or for the given entity in the current [Archetype]. This must always be called after
[FetchComponents::set_table] with a table_row in the range of the current [Table] or after
[FetchComponents::set_archetype] with a entity in the current archetype.
§Safety
Must always be called after [FetchComponents::set_table] or [FetchComponents::set_archetype]. entity and
table_row must be in the range of the current table and archetype.
If update_component_access includes any mutable accesses, then the caller must ensure
that fetch is called no more than once for each entity/table_row in each archetype.
If Self implements [ReadOnlyFetchComponents], then this can safely be called multiple times.
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.