pub struct QueryBorrow<'w, 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

Execute the query

Provide random access to the query results

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

Useful for distributing work over a threadpool.

Transform the query into one that requires a certain component without borrowing it

This can be useful when the component needs to be borrowed elsewhere and it isn’t necessary for the iterator to expose its data directly.

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!(entities.contains(&(a, 123)));
assert!(entities.contains(&(b, 456)));

Transform the query into one that skips entities having a certain component

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

Executes the destructor for this type. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.