pub struct EntityFetcher<'w> { /* private fields */ }Expand description
Provides a safe interface for non-structural access to the entities in a World.
This cannot add or remove components, or spawn or despawn entities,
making it relatively safe to access in concert with other ECS data.
This type can be constructed via World::entities_and_commands,
or DeferredWorld::entities_and_commands.
Implementations§
Source§impl<'w> EntityFetcher<'w>
impl<'w> EntityFetcher<'w>
Sourcepub fn get<F: WorldEntityFetch>(
&self,
entities: F,
) -> Result<F::Ref<'_>, EntityDoesNotExistError>
pub fn get<F: WorldEntityFetch>( &self, entities: F, ) -> Result<F::Ref<'_>, EntityDoesNotExistError>
Returns EntityRefs that expose read-only operations for the given
entities, returning Err if any of the given entities do not exist.
This function supports fetching a single entity or multiple entities:
- Pass an
Entityto receive a singleEntityRef. - Pass a slice of
Entitys to receive aVec<EntityRef>. - Pass an array of
Entitys to receive an equally-sized array ofEntityRefs. - Pass a reference to a
EntityHashSetto receive anEntityHashMap<EntityRef>.
§Errors
If any of the given entities do not exist in the world, the first
Entity found to be missing will return an EntityDoesNotExistError.
§Examples
For examples, see World::entity.
Sourcepub fn get_mut<F: WorldEntityFetch>(
&mut self,
entities: F,
) -> Result<F::DeferredMut<'_>, EntityMutableFetchError>
pub fn get_mut<F: WorldEntityFetch>( &mut self, entities: F, ) -> Result<F::DeferredMut<'_>, EntityMutableFetchError>
Returns EntityMuts that expose read and write operations for the
given entities, returning Err if any of the given entities do not
exist.
This function supports fetching a single entity or multiple entities:
- Pass an
Entityto receive a singleEntityMut.- This reference type allows for structural changes to the entity, such as adding or removing components, or despawning the entity.
- Pass a slice of
Entitys to receive aVec<EntityMut>. - Pass an array of
Entitys to receive an equally-sized array ofEntityMuts. - Pass a reference to a
EntityHashSetto receive anEntityHashMap<EntityMut>.
§Errors
- Returns
EntityMutableFetchError::EntityDoesNotExistif any of the givenentitiesdo not exist in the world.- Only the first entity found to be missing will be returned.
- Returns
EntityMutableFetchError::AliasedMutabilityif the same entity is requested multiple times.
§Examples
For examples, see DeferredWorld::entity_mut.