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 contains(&self, ent: Entity) -> bool
pub fn contains(&self, ent: Entity) -> bool
Check if an Entity is present in the map.
In contrast to get
, this does not require a S::Fetch: FetchShared
bound.
In contrast to get_mut
however, a shared borrow is sufficient.
§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, (2.0_f32,));
let mut query = Query::<(&i32, Option<&f32>)>::new();
let mut query = query.borrow(&world);
let query = query.map();
assert!(query.contains(entity1));
assert!(!query.contains(entity2));
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);
Trait Implementations§
Auto Trait Implementations§
impl<'q, S> RefUnwindSafe for QueryMap<'q, S>
impl<'q, S> Unpin for QueryMap<'q, S>
impl<'q, S> UnwindSafe for QueryMap<'q, 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