pub struct QueryRef<'w, S>where
S: QuerySpec,{ /* private fields */ }Implementations§
source§impl<S> QueryRef<'_, S>where
S: QuerySpec,
impl<S> QueryRef<'_, S>where S: QuerySpec,
sourcepub fn for_each<'q, F>(&'q mut self, f: F)where
F: FnMut(<S::Fetch as Fetch<'q>>::Item),
pub fn for_each<'q, F>(&'q mut self, f: F)where F: FnMut(<S::Fetch as Fetch<'q>>::Item),
Visit all entities matching the query.
sourcepub fn iter<'q>(&'q mut self) -> QueryIter<'q, S> ⓘ
pub fn iter<'q>(&'q mut self) -> QueryIter<'q, S> ⓘ
Create an iterator over the entities matching the query.
sourcepub fn par_iter<'q>(&'q mut self) -> QueryParIter<'q, S>where
<S::Fetch as Fetch<'q>>::Item: Send,
pub fn par_iter<'q>(&'q mut self) -> QueryParIter<'q, S>where <S::Fetch as Fetch<'q>>::Item: Send,
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;
});
},
);sourcepub fn map<'q>(&'q mut self) -> QueryMap<'q, S>
pub fn map<'q>(&'q mut self) -> QueryMap<'q, S>
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);