pub struct Query<T>(_, _)
where
    T: IsQuery + ?Sized
;
Expand description

Queries can be used iterate over matching bundles of components.

Querys are written as a tuple of component column types, where each position in the tuple denotes a column value in the resulting iteration tuple.

Below we use mutable and immutable reference types in our query to include either a mutable or immutable reference to those components:

use apecs::*;

struct Position(pub f32);
struct Velocity(pub f32);
struct Acceleration(pub f32);

let mut world = World::default();
{
    let mut entities: Write<Entities> = world.fetch().unwrap();
    for i in 0..100 {
        entities
            .create()
            .insert_bundle((Position(0.0), Velocity(0.0), Acceleration(i as f32)));
    }
}
{
    let q_accelerate: Query<(&mut Velocity, &Acceleration)> = world.fetch().unwrap();
    for (v, a) in q_accelerate.query().iter_mut() {
        v.0 += a.0;
    }
}
{
    let q_move: Query<(&mut Position, &Velocity)> = world.fetch().unwrap();
    for (p, v) in q_move.query().iter_mut() {
        p.0 += v.0;
    }
}

Implementations

Prepare the query, locking the columns needed to iterate over matching components.

Trait Implementations

Attempt to construct Self with the given LoanManager.

Return a plugin containing the systems and sub-resources required to create and use the type. 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 alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

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.