pub struct QueryRef<'w, S> where
S: QuerySpec, { /* private fields */ }
Implementations
sourceimpl<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>ⓘNotable traits for QueryIter<'q, S>impl<'q, S> Iterator for QueryIter<'q, S> where
S: QuerySpec, type Item = <S::Fetch as Fetch<'q>>::Item;
pub fn iter<'q>(&'q mut self) -> QueryIter<'q, S>ⓘNotable traits for QueryIter<'q, S>impl<'q, S> Iterator for QueryIter<'q, S> where
S: QuerySpec, type Item = <S::Fetch as Fetch<'q>>::Item;
S: QuerySpec, type Item = <S::Fetch as Fetch<'q>>::Item;
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);
Auto Trait Implementations
impl<'w, S> !RefUnwindSafe for QueryRef<'w, S>
impl<'w, S> !Send for QueryRef<'w, S>
impl<'w, S> !Sync for QueryRef<'w, S>
impl<'w, S> Unpin for QueryRef<'w, S> where
<<S as QuerySpec>::Fetch as Fetch<'w>>::Ref: Unpin,
impl<'w, S> !UnwindSafe for QueryRef<'w, S>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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