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
where Q: for<'x> Fetch<'x>,

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

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

Collect all elements in the query into a sorted 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, F::PushRight, S>
where F: TuplePush<G>,

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, F::PushRight, S>
where F: TuplePush<BatchSize>,

Limits the size of each batch using QueryBorrow::iter_batched

source

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

Shortcut for filter(with_relation)

source

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

Shortcut for filter(without_relation)

source

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

Shortcut for filter(without)

source

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

Shortcut for filter(with)

source

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

Borrow data in 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, dst: &mut 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<'_, '_, '_>) -> Self::Value

Get the data from the system context
source§

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

Human friendly debug description

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

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.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

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

Initializes a with the given initializer. Read more
source§

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

Dereferences the given pointer. Read more
source§

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

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where 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 T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ComponentValue for T
where T: Send + Sync + 'static,