Struct flax::query::Query

source ·
pub struct Query<Q, F = All, S = Planar> { /* private fields */ }
Expand description

Represents a query and state for a given world. The archetypes to visit is cached in the query which means it is more performant to reuse the query than creating a new one.

The archetype borrowing assures aliasing. Two of the same queries can be run at the same time as long as they don’t borrow an archetype’s component mutably at the same time.

Implementations§

source§

impl<Q> Query<Q, All, Planar>

source

pub fn new(fetch: Q) -> Self

Construct a new query which will fetch all items in the given query. The query can be either a singular component, a tuple of components, or any other type which implements crate::Fetch.

Note: The query will not yield components, as it may not be intended behaviour since the most common intent is the entities. See Query::with_components

A fetch may also contain filters Construct a new query which will fetch all items in the given query. The query can be either a singular component, a tuple of components, or any other type which implements crate::Fetch.

Note: The query will not yield components, as it may not be intended behaviour since the most common intent is the entities. See Query::with_components

A fetch may also contain filters Construct a new query which will fetch all items in the given query. The query can be either a singular component, a tuple of components, or any other type which implements crate::Fetch.

Note: The query will not yield components, as it may not be intended behaviour since the most common intent is the entities. See Query::with_components

A fetch may also contain filters

source

pub fn with_components(self) -> Self

Include components in a planar query.

Note: only relevant for the planar strategy

source§

impl<Q, F> Query<Q, F, Planar>where Q: for<'x> Fetch<'x>, F: for<'x> Fetch<'x>,

source

pub fn with_strategy<S>(self, strategy: S) -> Query<Q, F, S>where S: for<'w> QueryStrategy<'w, Q, F>,

Use the given [QueryStrategy].

This replaces the previous strategy

source

pub fn entity(self, id: Entity) -> EntityQuery<Q, F>where Entity: for<'w> QueryStrategy<'w, Q, F>,

Transform the query into a query for a single entity

source

pub fn topo<T: ComponentValue>( self, relation: impl RelationExt<T> ) -> Query<Q, F, Topo>where Topo: for<'w> QueryStrategy<'w, Q, F>,

Transform the query into a topologically ordered query

source

pub fn collect_vec<'w, T>(&'w mut self, world: &'w World) -> Vec<T>where T: 'static, Q: for<'q> FetchItem<'q, Item = T>,

Collect all elements in the query into a vector

source§

impl<Q, F, S> Query<Q, F, S>where Q: for<'x> Fetch<'x>, F: for<'x> Fetch<'x>,

source

pub fn filter<G>(self, filter: G) -> Query<Q, And<F, G>, S>

Adds a new filter to the query. This filter is and:ed with the existing filters.

source

pub fn batch_size(self, size: Slot) -> Query<Q, And<F, BatchSize>, S>

Limits the size of each batch using QueryBorrow::iter_batched

source

pub fn with_relation<T: ComponentValue>( self, rel: impl RelationExt<T> ) -> Query<Q, And<F, WithRelation>, S>

Shortcut for filter(with_relation)

source

pub fn without_relation<T: ComponentValue>( self, rel: impl RelationExt<T> ) -> Query<Q, And<F, WithoutRelation>, S>

Shortcut for filter(without_relation)

source

pub fn without<T: ComponentValue>( self, component: Component<T> ) -> Query<Q, And<F, Without>, S>

Shortcut for filter(without)

source

pub fn with<T: ComponentValue>( self, component: Component<T> ) -> Query<Q, And<F, With>, S>

Shortcut for filter(with)

source

pub fn borrow<'w>(&'w mut self, world: &'w World) -> S::Borrowwhere S: QueryStrategy<'w, Q, F>,

Borrow the world for the query.

The returned value holds the borrows of the query fetch. As such, all references from iteration or using QueryBorrow::get] will have a lifetime of the [QueryBorrow`.

This is because iterators can not yield references to internal state as all items returned by the iterator need to coexist.

It is safe to use the same prepared query for both iteration and random access, Rust’s borrow rules will ensure aliasing rules.

Trait Implementations§

source§

impl<Q: Clone, F: Clone, S: Clone> Clone for Query<Q, F, S>

source§

fn clone(&self) -> Query<Q, F, S>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Q, F, S: Debug> Debug for Query<Q, F, S>where Q: for<'x> Fetch<'x> + Debug, F: for<'x> Fetch<'x> + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Q, F, S> SystemAccess for Query<Q, F, S>where Q: 'static + for<'x> Fetch<'x>, F: 'static + for<'x> Fetch<'x>, S: for<'x> QueryStrategy<'x, Q, F>,

source§

fn access(&self, world: &World) -> Vec<Access>

Returns all the accesses for a system
source§

impl<'a, Q, F, S> SystemData<'a> for Query<Q, F, S>where Q: 'static + for<'x> Fetch<'x>, F: 'static + for<'x> Fetch<'x>, S: 'static + for<'x> QueryStrategy<'x, Q, F>,

§

type Value = QueryData<'a, Q, F, S>

The borrow from the system context
source§

fn acquire(&'a mut self, ctx: &'a SystemContext<'_>) -> Result<Self::Value>

Get the data from the system context

Auto Trait Implementations§

§

impl<Q, F, S> RefUnwindSafe for Query<Q, F, S>where F: RefUnwindSafe, Q: RefUnwindSafe, S: RefUnwindSafe,

§

impl<Q, F, S> Send for Query<Q, F, S>where F: Send, Q: Send, S: Send,

§

impl<Q, F, S> Sync for Query<Q, F, S>where F: Sync, Q: Sync, S: Sync,

§

impl<Q, F, S> Unpin for Query<Q, F, S>where F: Unpin, Q: Unpin, S: Unpin,

§

impl<Q, F, S> UnwindSafe for Query<Q, F, S>where F: UnwindSafe, Q: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.