pub struct QueryRef<'w, S> where
    S: QuerySpec
{ /* private fields */ }
Expand description

Borrow of the World for a Query. Required to obtain an iterator.

Implementations

Visit all entities matching the query.

Create an iterator over the entities matching the query.

Create a parallel iterator over the entities matching the query.

Examples
use rayon::join;

let mut world = World::new();

let entity1 = world.alloc();
world.insert(entity1, (42_i32, 23_u32, 1.0_f32));

let entity2 = world.alloc();
world.insert(entity2, (0_i32, true));

let mut query1 = Query::<&mut i32>::new();
let mut ref1 = query1.borrow(&world);
let mut iter1 = ref1.iter();

let mut query2 = Query::<(&u32, &mut f32)>::new();
let mut ref2 = query2.borrow(&world);
let mut iter2 = ref2.par_iter();

join(
    move || {
        for i in iter1 {
            *i -= 1;
        }
    },
    move || {
        iter2.for_each(|(u, f)| {
            *f += *u as f32;
        });
    },
);

Create a map of the entities matching the query.

This is an alternative to get and get_mut for repeated calls, to amortize the set-up costs.

Examples
let mut world = World::new();

let entity = world.alloc();
world.insert(entity, (42_i32, 1.0_f32));

let mut query = Query::<(&i32, &f32)>::new();
let mut query = query.borrow(&world);
let mut query = query.map();

let (i, f) = query.get_mut(entity).unwrap();

assert_eq!(*i, 42);
assert_eq!(*f, 1.0);

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.