Struct Fetcher

Source
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,

Source

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.

Source

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.

Source

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.

Source

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:

  1. AliasedMutability if the given array contains any duplicate EntityIds.
  2. NoSuchEntity if any of the entities do not exist.
  3. QueryDoesNotMatch if any of the entities do not match the Query of this fetcher.
Source

pub fn iter(&self) -> Iter<'_, Q>
where Q: ReadOnlyQuery,

Returns an iterator over all entities matching the read-only query.

Source

pub fn iter_mut(&mut self) -> Iter<'_, Q>

Returns an iterator over all entities matching the query.

Trait Implementations§

Source§

impl<'a, Q> Debug for Fetcher<'a, Q>
where Q: Query,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<Q> HandlerParam for Fetcher<'_, Q>
where Q: Query + 'static,

Source§

type State = FetcherState<Q>

Persistent data stored in the handler.
Source§

type This<'a> = Fetcher<'a, Q>

The type produced by this handler param. This must be the type of Self but with the lifetime of 'a.
Source§

fn init( world: &mut World, config: &mut HandlerConfig, ) -> Result<<Fetcher<'_, Q> as HandlerParam>::State, InitError>

Initializes the handler using the input World and HandlerConfig. Read more
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>

Obtains a new instance of the handler parameter. Read more
Source§

fn refresh_archetype( state: &mut <Fetcher<'_, Q> as HandlerParam>::State, arch: &Archetype, )

Refresh an archetype for this handler param. Called whenever Handler::refresh_archetype is called.
Source§

fn remove_archetype( state: &mut <Fetcher<'_, Q> as HandlerParam>::State, arch: &Archetype, )

Remove the given archetype for this handler param. Called whenever Handler::remove_archetype is called.
Source§

impl<'a, Q> IntoIterator for &'a Fetcher<'_, Q>
where Q: ReadOnlyQuery,

Source§

type Item = <Q as Query>::Item<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Q>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a Fetcher<'_, Q> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, Q> IntoIterator for &'a mut Fetcher<'_, Q>
where Q: Query,

Source§

type Item = <Q as Query>::Item<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Q>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a mut Fetcher<'_, Q> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, Q> IntoIterator for Fetcher<'a, Q>
where Q: Query,

Source§

type Item = <Q as Query>::Item<'a>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Q>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <Fetcher<'a, Q> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, Q> Send for Fetcher<'a, Q>
where Q: Query, <Q as Query>::Item<'a>: Send,

Source§

impl<'a, Q> Sync for Fetcher<'a, Q>
where Q: Query, <Q as Query>::Item<'a>: Sync,

Auto Trait Implementations§

§

impl<'a, Q> Freeze for Fetcher<'a, Q>

§

impl<'a, Q> !RefUnwindSafe for Fetcher<'a, Q>

§

impl<'a, Q> Unpin for Fetcher<'a, Q>

§

impl<'a, Q> !UnwindSafe for Fetcher<'a, Q>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more