pub struct Fetcher<'a, Q>where
Q: Query,{ /* private fields */ }
Expand description
A HandlerParam
for accessing data from entities matching a given
Query
.
For more information, see the relevant tutorial chapter.
Implementations§
Source§impl<'a, Q> Fetcher<'a, Q>where
Q: Query,
impl<'a, Q> Fetcher<'a, Q>where
Q: Query,
Sourcepub fn get(&self, entity: EntityId) -> Result<<Q as Query>::Item<'_>, GetError>where
Q: ReadOnlyQuery,
pub fn get(&self, entity: EntityId) -> Result<<Q as Query>::Item<'_>, GetError>where
Q: ReadOnlyQuery,
Returns the read-only query item for the given entity.
If the entity doesn’t exist or doesn’t match the query, then a
GetError
is returned.
Sourcepub unsafe fn get_unchecked(
&self,
entity: EntityId,
) -> Result<<Q as Query>::Item<'_>, GetError>
pub unsafe fn get_unchecked( &self, entity: EntityId, ) -> Result<<Q as Query>::Item<'_>, GetError>
Returns the query item for the given entity without checking borrowing rules.
This is useful when you know the entity IDs are disjoint but can’t prove it to the compiler.
If the entity doesn’t exist or doesn’t match the query, then a
GetError
is returned.
§Safety
You must ensure that all entities that co-occur are disjoint if they contain any mutable references.
Sourcepub fn get_mut(
&mut self,
entity: EntityId,
) -> Result<<Q as Query>::Item<'_>, GetError>
pub fn get_mut( &mut self, entity: EntityId, ) -> Result<<Q as Query>::Item<'_>, GetError>
Returns the query item for the given entity.
If the entity doesn’t exist or doesn’t match the query, then a
GetError
is returned.
Sourcepub fn get_many_mut<const N: usize>(
&mut self,
entities: [EntityId; N],
) -> Result<[<Q as Query>::Item<'_>; N], GetManyMutError>
pub fn get_many_mut<const N: usize>( &mut self, entities: [EntityId; N], ) -> Result<[<Q as Query>::Item<'_>; N], GetManyMutError>
Returns the query items for the given array of entities.
An error of type GetManyMutError
is returned in the following
scenarios:
AliasedMutability
if the given array contains any duplicateEntityId
s.NoSuchEntity
if any of the entities do not exist.QueryDoesNotMatch
if any of the entities do not match theQuery
of this fetcher.
Sourcepub fn iter(&self) -> Iter<'_, Q>where
Q: ReadOnlyQuery,
pub fn iter(&self) -> Iter<'_, Q>where
Q: ReadOnlyQuery,
Returns an iterator over all entities matching the read-only query.
Trait Implementations§
Source§impl<Q> HandlerParam for Fetcher<'_, Q>where
Q: Query + 'static,
impl<Q> HandlerParam for Fetcher<'_, Q>where
Q: Query + 'static,
Source§type This<'a> = Fetcher<'a, Q>
type This<'a> = Fetcher<'a, Q>
Self
but with the lifetime of 'a
.Source§fn init(
world: &mut World,
config: &mut HandlerConfig,
) -> Result<<Fetcher<'_, Q> as HandlerParam>::State, InitError>
fn init( world: &mut World, config: &mut HandlerConfig, ) -> Result<<Fetcher<'_, Q> as HandlerParam>::State, InitError>
Source§unsafe fn get<'a>(
state: &'a mut <Fetcher<'_, Q> as HandlerParam>::State,
_info: &'a HandlerInfo,
_event_ptr: EventPtr<'a>,
_target_location: EntityLocation,
world: UnsafeWorldCell<'a>,
) -> <Fetcher<'_, Q> as HandlerParam>::This<'a>
unsafe fn get<'a>( state: &'a mut <Fetcher<'_, Q> as HandlerParam>::State, _info: &'a HandlerInfo, _event_ptr: EventPtr<'a>, _target_location: EntityLocation, world: UnsafeWorldCell<'a>, ) -> <Fetcher<'_, Q> as HandlerParam>::This<'a>
Source§fn refresh_archetype(
state: &mut <Fetcher<'_, Q> as HandlerParam>::State,
arch: &Archetype,
)
fn refresh_archetype( state: &mut <Fetcher<'_, Q> as HandlerParam>::State, arch: &Archetype, )
Handler::refresh_archetype
is called.Source§fn remove_archetype(
state: &mut <Fetcher<'_, Q> as HandlerParam>::State,
arch: &Archetype,
)
fn remove_archetype( state: &mut <Fetcher<'_, Q> as HandlerParam>::State, arch: &Archetype, )
Handler::remove_archetype
is called.