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>
impl<Q> Query<Q, All, Planar>
sourcepub fn new(fetch: Q) -> Selfwhere
Q: for<'x> Fetch<'x>,
pub fn new(fetch: Q) -> Selfwhere
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
sourcepub fn with_components(self) -> Self
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>
impl<Q, F> Query<Q, F, Planar>
sourcepub fn with_strategy<S>(self, strategy: S) -> Query<Q, F, S>where
S: for<'w> QueryStrategy<'w, Q, F>,
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
sourcepub fn entity(self, id: Entity) -> EntityQuery<Q, F>where
Entity: for<'w> QueryStrategy<'w, Q, F>,
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
sourcepub fn topo<T: ComponentValue>(
self,
relation: impl RelationExt<T>
) -> Query<Q, F, Topo>where
Topo: for<'w> QueryStrategy<'w, Q, F>,
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
sourcepub fn collect_vec<'w, T>(&'w mut self, world: &'w World) -> Vec<T>where
T: 'static,
Q: for<'q> FetchItem<'q, Item = T>,
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>
impl<Q, F, S> Query<Q, F, S>
sourcepub fn filter<G>(self, filter: G) -> Query<Q, F::PushRight, S>where
F: TuplePush<G>,
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.
sourcepub fn batch_size(self, size: Slot) -> Query<Q, F::PushRight, S>where
F: TuplePush<BatchSize>,
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
sourcepub fn with_relation<T: ComponentValue>(
self,
rel: impl RelationExt<T>
) -> Query<Q, F::PushRight, S>where
F: TuplePush<WithRelation>,
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)
sourcepub fn without_relation<T: ComponentValue>(
self,
rel: impl RelationExt<T>
) -> Query<Q, F::PushRight, S>where
F: TuplePush<WithoutRelation>,
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)
sourcepub fn without<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, F::PushRight, S>where
F: TuplePush<Without>,
pub fn without<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, F::PushRight, S>where
F: TuplePush<Without>,
Shortcut for filter(without)
sourcepub fn with<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, F::PushRight, S>where
F: TuplePush<With>,
pub fn with<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, F::PushRight, S>where
F: TuplePush<With>,
Shortcut for filter(with)
sourcepub fn borrow<'w>(&'w mut self, world: &'w World) -> S::Borrowwhere
S: QueryStrategy<'w, Q, F>,
pub fn borrow<'w>(&'w mut self, world: &'w World) -> S::Borrowwhere
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.