pub struct QueryMap<'q, S>where
S: QuerySpec,{ /* private fields */ }Expand description
Provides random access to the entities which match a certain Query.
Implementations§
source§impl<S> QueryMap<'_, S>where
S: QuerySpec,
impl<S> QueryMap<'_, S>where S: QuerySpec,
sourcepub fn get(&self, ent: Entity) -> Option<<S::Fetch as Fetch<'_>>::Item>where
S::Fetch: FetchShared,
pub fn get(&self, ent: Entity) -> Option<<S::Fetch as Fetch<'_>>::Item>where S::Fetch: FetchShared,
Access the queried components of the given Entity
Available only if the components do not include unique references.
Examples
let mut world = World::new();
let entity1 = world.alloc();
world.insert(entity1, (42_i32, 1.0_f32));
let entity2 = world.alloc();
world.insert(entity2, (23_i32,));
let mut query = Query::<(&i32, Option<&f32>)>::new();
let mut query = query.borrow(&world);
let mut query = query.map();
let (i1, f1) = query.get(entity1).unwrap();
let (i2, f2) = query.get(entity2).unwrap();
assert_eq!(*i1, 42);
assert_eq!(f1.copied(), Some(1.0));
assert_eq!(*i2, 23);
assert_eq!(f2.copied(), None);sourcepub fn get_mut(&mut self, ent: Entity) -> Option<<S::Fetch as Fetch<'_>>::Item>
pub fn get_mut(&mut self, ent: Entity) -> Option<<S::Fetch as Fetch<'_>>::Item>
Exclusively access the queried components of the given Entity
sourcepub fn get_many_mut<const N: usize>(
&mut self,
ent: [Entity; N]
) -> [Option<<S::Fetch as Fetch<'_>>::Item>; N]
pub fn get_many_mut<const N: usize>( &mut self, ent: [Entity; N] ) -> [Option<<S::Fetch as Fetch<'_>>::Item>; N]
Exclusively access the queried component of the given distinct entities
Examples
let mut world = World::new();
let entity1 = world.alloc();
world.insert(entity1, (42_i32, 1.0_f32));
let entity2 = world.alloc();
world.insert(entity2, (23_i32,));
let mut query = Query::<&mut i32>::new();
let mut query = query.borrow(&world);
let mut query = query.map();
let [i1, i2] = query.get_many_mut([entity1, entity2]);
assert_eq!(*i1.unwrap(), 42);
assert_eq!(*i2.unwrap(), 23);