logo
pub unsafe trait Fetch<'world> {
    type Item;
    type State: FetchState;

    const IS_DENSE: bool;
    const IS_ARCHETYPAL: bool;

    unsafe fn init(
        world: &'world World,
        state: &Self::State,
        last_change_tick: u32,
        change_tick: u32
    ) -> Self; unsafe fn set_archetype(
        &mut self,
        state: &Self::State,
        archetype: &'world Archetype,
        tables: &'world Tables
    ); unsafe fn set_table(&mut self, state: &Self::State, table: &'world Table); unsafe fn archetype_fetch(&mut self, archetype_index: usize) -> Self::Item; unsafe fn table_fetch(&mut self, table_row: usize) -> Self::Item; fn update_component_access(
        state: &Self::State,
        access: &mut FilteredAccess<ComponentId>
    ); fn update_archetype_component_access(
        state: &Self::State,
        archetype: &Archetype,
        access: &mut Access<ArchetypeComponentId>
    ); unsafe fn archetype_filter_fetch(&mut self, archetype_index: usize) -> bool { ... } unsafe fn table_filter_fetch(&mut self, table_row: usize) -> bool { ... } }
Expand description

Types that implement this trait are responsible for fetching query items from tables or archetypes.

Every type that implements WorldQuery have their associated WorldQuery::Fetch and WorldQuery::State types that are essential for fetching component data.

Safety

Implementor must ensure that Fetch::update_component_access and Fetch::update_archetype_component_access exactly reflects the results of FetchState::matches_component_set, Fetch::archetype_fetch, and Fetch::table_fetch.

Required Associated Types

Required Associated Constants

Returns true if (and only if) every table of every archetype matched by this fetch contains all of the matched components. This is used to select a more efficient “table iterator” for “dense” queries. If this returns true, Fetch::set_table and Fetch::table_fetch will be called for iterators. If this returns false, Fetch::set_archetype and Fetch::archetype_fetch will be called for iterators.

Returns true if (and only if) this Fetch relies strictly on archetypes to limit which components are accessed by the Query.

This enables optimizations for crate::query::QueryIter that rely on knowing exactly how many elements are being iterated (such as Iterator::collect()).

Required Methods

Creates a new instance of this fetch.

Safety

state must have been initialized (via FetchState::init) using the same world passed in to this function.

Adjusts internal state to account for the next Archetype. This will always be called on archetypes that match this Fetch.

Safety

archetype and tables must be from the World Fetch::init was called on. state must be the Self::State this was initialized with.

Adjusts internal state to account for the next Table. This will always be called on tables that match this Fetch.

Safety

table must be from the World Fetch::init was called on. state must be the Self::State this was initialized with.

Fetch Self::Item for the given archetype_index in the current Archetype. This must always be called after Fetch::set_archetype with an archetype_index in the range of the current Archetype

Safety

Must always be called after Fetch::set_archetype. archetype_index must be in the range of the current archetype

Fetch Self::Item for the given table_row in the current Table. This must always be called after Fetch::set_table with a table_row in the range of the current Table

Safety

Must always be called after Fetch::set_table. table_row must be in the range of the current table

Provided Methods

Safety

Must always be called after Fetch::set_archetype. archetype_index must be in the range of the current archetype.

Safety

Must always be called after Fetch::set_table. table_row must be in the range of the current table.

Implementations on Foreign Types

Implementors