pub struct Query<Q, F = All>where
Q: for<'x> Fetch<'x>,
F: for<'x> Filter<'x>,{ /* 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
sourceimpl<Q> Query<Q>where
Q: for<'x> Fetch<'x>,
impl<Q> Query<Q>where
Q: for<'x> Fetch<'x>,
sourcepub fn new(query: Q) -> Self
pub fn new(query: 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
sourceimpl<Q> Query<Q, All>where
Q: for<'x> Fetch<'x>,
impl<Q> Query<Q, All>where
Q: for<'x> Fetch<'x>,
sourcepub fn with_components(self) -> Self
pub fn with_components(self) -> Self
Include component entities for the query. The default is to hide components as they are usually not desired during iteration.
sourceimpl<Q, F> Query<Q, F>where
Q: for<'x> Fetch<'x>,
F: for<'x> Filter<'x>,
impl<Q, F> Query<Q, F>where
Q: for<'x> Fetch<'x>,
F: for<'x> Filter<'x>,
sourcepub fn filter<G: for<'x> Filter<'x>>(self, filter: G) -> Query<Q, And<F, G>>
pub fn filter<G: for<'x> Filter<'x>>(self, filter: G) -> Query<Q, And<F, G>>
Adds a new filter to the query. This filter is and:ed with the existing filters.
sourcepub fn without<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, And<F, Without>>
pub fn without<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, And<F, Without>>
Shortcut for filter(without)
sourcepub fn with<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, And<F, With>>
pub fn with<T: ComponentValue>(
self,
component: Component<T>
) -> Query<Q, And<F, With>>
Shortcut for filter(with)
sourcepub fn change_tick(&self) -> u32
pub fn change_tick(&self) -> u32
Returns the last change tick the query was run on. Any changes > change_tick will be yielded in a query iteration.
sourcepub fn borrow<'w>(&'w mut self, world: &'w World) -> QueryBorrow<'w, Q, F>
pub fn borrow<'w>(&'w mut self, world: &'w World) -> QueryBorrow<'w, Q, F>
Borrow the world for the query.
Allows for both random access and efficient iteration.
See: QueryBorrow::get and QueryBorrow::iter
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
sourceimpl<Q: Clone, F: Clone> Clone for Query<Q, F>where
Q: for<'x> Fetch<'x>,
F: for<'x> Filter<'x>,
impl<Q: Clone, F: Clone> Clone for Query<Q, F>where
Q: for<'x> Fetch<'x>,
F: for<'x> Filter<'x>,
sourceimpl<Q, F> SystemAccess for Query<Q, F>where
Q: for<'x> Fetch<'x>,
F: for<'x> Filter<'x>,
impl<Q, F> SystemAccess for Query<Q, F>where
Q: for<'x> Fetch<'x>,
F: for<'x> Filter<'x>,
Auto Trait Implementations
impl<Q, F> RefUnwindSafe for Query<Q, F>where
F: RefUnwindSafe,
Q: RefUnwindSafe,
impl<Q, F> Send for Query<Q, F>where
F: Send,
Q: Send,
impl<Q, F> Sync for Query<Q, F>where
F: Sync,
Q: Sync,
impl<Q, F> Unpin for Query<Q, F>where
F: Unpin,
Q: Unpin,
impl<Q, F> UnwindSafe for Query<Q, F>where
F: UnwindSafe,
Q: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more