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 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>
pub fn par_iter<'q>(&'q mut self) -> QueryParIter<'q, S>
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 query_one
for repeated calls, to amortize the set-up costs of random access.
§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>
impl<'w, S> !UnwindSafe for QueryRef<'w, S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more