Trait WorldQuery

Source
pub trait WorldQuery {
    type Item<'a>;

    // Required methods
    fn type_ids() -> Vec<TypeId>;
    unsafe fn fetch<'a>(
        page_ptr: *const ComponentPage,
        row_index: usize,
    ) -> Self::Item<'a>;

    // Provided method
    fn without_type_ids() -> Vec<TypeId> { ... }
}
Expand description

A trait implemented by types that can be used to query data from the World.

This “sealed” trait provides the necessary information for the query engine to find the correct pages and safely access component data. It is implemented for component references (&T, &mut T), EntityId, filters like Without<T>, and tuples of other WorldQuery types.

Required Associated Types§

Source

type Item<'a>

The type of item that the query iterator will yield (e.g., (&'a Position, &'a mut Velocity)).

Required Methods§

Source

fn type_ids() -> Vec<TypeId>

Returns the sorted list of TypeIds for the components to be INCLUDED in the query. This signature is used to find ComponentPages that contain all these components.

Source

unsafe fn fetch<'a>( page_ptr: *const ComponentPage, row_index: usize, ) -> Self::Item<'a>

Fetches the query’s item from a specific row in a ComponentPage.

§Safety

This function is unsafe because the caller (the Query iterator) must guarantee several invariants:

  1. The page pointed to by page_ptr is valid and matches the query’s signature.
  2. row_index is a valid index within the page’s columns.
  3. Aliasing rules are not violated (e.g., no two &mut T to the same data).

Provided Methods§

Source

fn without_type_ids() -> Vec<TypeId>

Returns the sorted list of TypeIds for components to be EXCLUDED from the query. Used to filter out pages that contain these components.

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.

Implementations on Foreign Types§

Source§

impl<Q1: WorldQuery, Q2: WorldQuery> WorldQuery for (Q1, Q2)

Source§

type Item<'a> = (<Q1 as WorldQuery>::Item<'a>, <Q2 as WorldQuery>::Item<'a>)

Source§

fn type_ids() -> Vec<TypeId>

Source§

fn without_type_ids() -> Vec<TypeId>

Source§

unsafe fn fetch<'a>( page_ptr: *const ComponentPage, row_index: usize, ) -> Self::Item<'a>

Source§

impl<Q1: WorldQuery, Q2: WorldQuery, Q3: WorldQuery> WorldQuery for (Q1, Q2, Q3)

Source§

type Item<'a> = (<Q1 as WorldQuery>::Item<'a>, <Q2 as WorldQuery>::Item<'a>, <Q3 as WorldQuery>::Item<'a>)

Source§

fn type_ids() -> Vec<TypeId>

Source§

fn without_type_ids() -> Vec<TypeId>

Source§

unsafe fn fetch<'a>( page_ptr: *const ComponentPage, row_index: usize, ) -> Self::Item<'a>

Source§

impl<Q1: WorldQuery, Q2: WorldQuery, Q3: WorldQuery, Q4: WorldQuery> WorldQuery for (Q1, Q2, Q3, Q4)

Source§

type Item<'a> = (<Q1 as WorldQuery>::Item<'a>, <Q2 as WorldQuery>::Item<'a>, <Q3 as WorldQuery>::Item<'a>, <Q4 as WorldQuery>::Item<'a>)

Source§

fn type_ids() -> Vec<TypeId>

Source§

fn without_type_ids() -> Vec<TypeId>

Source§

unsafe fn fetch<'a>( page_ptr: *const ComponentPage, row_index: usize, ) -> Self::Item<'a>

Source§

impl<T: Component> WorldQuery for &T

Source§

unsafe fn fetch<'a>( page_ptr: *const ComponentPage, row_index: usize, ) -> Self::Item<'a>

Fetches a reference to the component T from the specified row.

§Safety

The caller MUST guarantee that the page contains a column for component T and that row_index is in bounds.

Source§

type Item<'a> = &'a T

Source§

fn type_ids() -> Vec<TypeId>

Source§

impl<T: Component> WorldQuery for &mut T

Source§

unsafe fn fetch<'a>( page_ptr: *const ComponentPage, row_index: usize, ) -> Self::Item<'a>

Fetches a mutable reference to the component T from the specified row.

§Safety

The caller MUST guarantee that:

  1. The page contains a column for component T.
  2. row_index is in bounds.
  3. No other mutable reference to this specific component exists at the same time. The query engine must enforce this.
Source§

type Item<'a> = &'a mut T

Source§

fn type_ids() -> Vec<TypeId>

Implementors§