bevy_ecs::query

Trait QueryFilter

Source
pub trait QueryFilter: WorldQuery {
    const IS_ARCHETYPAL: bool;

    // Required method
    unsafe fn filter_fetch(
        fetch: &mut Self::Fetch<'_>,
        entity: Entity,
        table_row: TableRow,
    ) -> bool;
}
Expand description

Types that filter the results of a Query.

There are many types that natively implement this trait:

  • Component filters. With and Without filters can be applied to check if the queried entity does or does not contain a particular component.
  • Change detection filters. Added and Changed filters can be applied to detect component changes to an entity.
  • QueryFilter tuples. If every element of a tuple implements QueryFilter, then the tuple itself also implements the same trait. This enables a single Query to filter over multiple conditions. Due to the current lack of variadic generics in Rust, the trait has been implemented for tuples from 0 to 15 elements, but nesting of tuples allows infinite QueryFilters.
  • Filter disjunction operator. By default, tuples compose query filters in such a way that all conditions must be satisfied to generate a query item for a given entity. Wrapping a tuple inside an Or operator will relax the requirement to just one condition.

Implementing the trait manually can allow for a fundamentally new type of behavior.

Query design can be easily structured by deriving QueryFilter for custom types. Despite the added complexity, this approach has several advantages over using QueryFilter tuples. The most relevant improvements are:

  • Reusability across multiple systems.
  • Filters can be composed together to create a more complex filter.

This trait can only be derived for structs if each field also implements QueryFilter.

#[derive(QueryFilter)]
struct MyFilter<T: Component, P: Component> {
    // Field names are not relevant, since they are never manually accessed.
    with_a: With<ComponentA>,
    or_filter: Or<(With<ComponentC>, Added<ComponentB>)>,
    generic_tuple: (With<T>, Without<P>),
}

fn my_system(query: Query<Entity, MyFilter<ComponentD, ComponentE>>) {
    // ...
}

Required Associated Constants§

Source

const IS_ARCHETYPAL: bool

Returns true if (and only if) this Filter 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§

Source

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, entity: Entity, table_row: TableRow, ) -> bool

Returns true if the provided Entity and TableRow should be included in the query results. If false, the entity will be skipped.

Note that this is called after already restricting the matched Tables and Archetypes to the ones that are compatible with the Filter’s access.

§Safety

Must always be called after WorldQuery::set_table or WorldQuery::set_archetype. entity and table_row must be in the range of the current table and archetype.

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 QueryFilter for ()

Source§

const IS_ARCHETYPAL: bool = true

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter> QueryFilter for (F0,)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter> QueryFilter for (F0, F1)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter> QueryFilter for (F0, F1, F2)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter> QueryFilter for (F0, F1, F2, F3)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7, F8)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter, F12: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter, F12: QueryFilter, F13: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter, F12: QueryFilter, F13: QueryFilter, F14: QueryFilter> QueryFilter for (F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)

Source§

const IS_ARCHETYPAL: bool = _

Source§

unsafe fn filter_fetch( fetch: &mut Self::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Implementors§

Source§

impl QueryFilter for Or<()>

Source§

impl<F0: QueryFilter> QueryFilter for Or<(F0,)>

Source§

impl<F0: QueryFilter, F1: QueryFilter> QueryFilter for Or<(F0, F1)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter> QueryFilter for Or<(F0, F1, F2)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7, F8)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter, F12: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter, F12: QueryFilter, F13: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13)>

Source§

impl<F0: QueryFilter, F1: QueryFilter, F2: QueryFilter, F3: QueryFilter, F4: QueryFilter, F5: QueryFilter, F6: QueryFilter, F7: QueryFilter, F8: QueryFilter, F9: QueryFilter, F10: QueryFilter, F11: QueryFilter, F12: QueryFilter, F13: QueryFilter, F14: QueryFilter> QueryFilter for Or<(F0, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14)>

Source§

impl<T: Component> QueryFilter for Added<T>

Source§

impl<T: Component> QueryFilter for Changed<T>

Source§

impl<T: Component> QueryFilter for With<T>

Source§

impl<T: Component> QueryFilter for Without<T>