pub struct QueryBorrow<'w, Q>where
    Q: Query,{ /* private fields */ }
Expand description

A borrow of a World sufficient to execute the query Q

Note that borrows are not released until this object is dropped.

Implementations§

§

impl<'w, Q> QueryBorrow<'w, Q>where Q: Query,

pub fn iter(&mut self) -> QueryIter<'_, Q>

Execute the query

pub fn view(&mut self) -> View<'_, Q>

Provide random access to the query results

pub fn iter_batched(&mut self, batch_size: u32) -> BatchedIter<'_, Q>

Like iter, but returns child iterators of at most batch_size elements

Useful for distributing work over a threadpool.

pub fn with<R>(self) -> QueryBorrow<'w, With<Q, R>>where R: Query,

Transform the query into one that requires another query be satisfied

Convenient when the values of the components in the other query are not of interest.

Equivalent to using a query type wrapped in With.

Example
let mut world = World::new();
let a = world.spawn((123, true, "abc"));
let b = world.spawn((456, false));
let c = world.spawn((42, "def"));
let entities = world.query::<&i32>()
    .with::<&bool>()
    .iter()
    .map(|(e, &i)| (e, i)) // Copy out of the world
    .collect::<Vec<_>>();
assert_eq!(entities.len(), 2);
assert!(entities.contains(&(a, 123)));
assert!(entities.contains(&(b, 456)));

pub fn without<R>(self) -> QueryBorrow<'w, Without<Q, R>>where R: Query,

Transform the query into one that skips entities satisfying another

Equivalent to using a query type wrapped in Without.

Example
let mut world = World::new();
let a = world.spawn((123, true, "abc"));
let b = world.spawn((456, false));
let c = world.spawn((42, "def"));
let entities = world.query::<&i32>()
    .without::<&bool>()
    .iter()
    .map(|(e, &i)| (e, i)) // Copy out of the world
    .collect::<Vec<_>>();
assert_eq!(entities, &[(c, 42)]);

Trait Implementations§

§

impl<'w, Q> Drop for QueryBorrow<'w, Q>where Q: Query,

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl<'q, 'w, Q> IntoIterator for &'q mut QueryBorrow<'w, Q>where Q: Query,

§

type Item = (Entity, <Q as Query>::Item<'q>)

The type of the elements being iterated over.
§

type IntoIter = QueryIter<'q, Q>

Which kind of iterator are we turning this into?
§

fn into_iter(self) -> <&'q mut QueryBorrow<'w, Q> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
§

impl<'w, Q> Send for QueryBorrow<'w, Q>where Q: Query, <Q as Query>::Item<'a>: for<'a> Send,

§

impl<'w, Q> Sync for QueryBorrow<'w, Q>where Q: Query, <Q as Query>::Item<'a>: for<'a> Send,

Auto Trait Implementations§

§

impl<'w, Q> RefUnwindSafe for QueryBorrow<'w, Q>where Q: RefUnwindSafe,

§

impl<'w, Q> Unpin for QueryBorrow<'w, Q>where Q: Unpin,

§

impl<'w, Q> UnwindSafe for QueryBorrow<'w, Q>where Q: 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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Finalize for T

§

unsafe fn finalize_raw(data: *mut ())

Safety Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V