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
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Query<T>
impl<T: ?Sized> Send for Query<T>where
T: Send,
impl<T: ?Sized> Sync for Query<T>where
T: Sync,
impl<T: ?Sized> Unpin for Query<T>where
T: Unpin,
impl<T> !UnwindSafe for Query<T>
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