Struct hecs::QueryBorrow

source ·
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 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)));

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§

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.