Struct QueryState

Source
pub struct QueryState<Q, F = ()>{ /* private fields */ }
Expand description

Provides scoped access to a World state according to a given WorldQuery and query filter.

Implementations§

Source§

impl<Q, F> QueryState<Q, F>

Source

pub fn new(world: &mut World) -> QueryState<Q, F>

Creates a new QueryState from a given World and inherits the result of world.id().

Source

pub fn is_empty( &self, world: &World, last_change_tick: u32, change_tick: u32, ) -> bool

Checks if the query is empty for the given World, where the last change and current tick are given.

Source

pub fn update_archetypes(&mut self, world: &World)

Takes a query for the given World, checks if the given world is the same as the query, and generates new archetypes for the given world.

§Panics

Panics if the world.id() does not equal the current QueryState internal id.

Source

pub fn validate_world(&self, world: &World)

Source

pub fn new_archetype(&mut self, archetype: &Archetype)

Creates a new Archetype.

Source

pub fn get<'w, 's>( &'s mut self, world: &'w World, entity: Entity, ) -> Result<<<Q as WorldQuery>::ReadOnlyFetch as Fetch<'w, 's>>::Item, QueryEntityError>

Gets the query result for the given World and Entity.

This can only be called for read-only queries, see Self::get_mut for write-queries.

Source

pub fn get_mut<'w, 's>( &'s mut self, world: &'w mut World, entity: Entity, ) -> Result<<<Q as WorldQuery>::Fetch as Fetch<'w, 's>>::Item, QueryEntityError>

Gets the query result for the given World and Entity.

Source

pub fn get_manual<'w, 's>( &'s self, world: &'w World, entity: Entity, ) -> Result<<<Q as WorldQuery>::ReadOnlyFetch as Fetch<'w, 's>>::Item, QueryEntityError>

Source

pub unsafe fn get_unchecked<'w, 's>( &'s mut self, world: &'w World, entity: Entity, ) -> Result<<<Q as WorldQuery>::Fetch as Fetch<'w, 's>>::Item, QueryEntityError>

Gets the query result for the given World and Entity.

§Safety

This does not check for mutable query correctness. To be safe, make sure mutable queries have unique access to the components they query.

Source

pub fn iter<'w, 's>( &'s mut self, world: &'w World, ) -> QueryIter<'w, 's, Q, <Q as WorldQuery>::ReadOnlyFetch, F>

Returns an Iterator over the query results for the given World.

This can only be called for read-only queries, see Self::iter_mut for write-queries.

Source

pub fn iter_mut<'w, 's>( &'s mut self, world: &'w mut World, ) -> QueryIter<'w, 's, Q, <Q as WorldQuery>::Fetch, F>

Returns an Iterator over the query results for the given World.

Source

pub fn iter_manual<'w, 's>( &'s self, world: &'w World, ) -> QueryIter<'w, 's, Q, <Q as WorldQuery>::ReadOnlyFetch, F>

Returns an Iterator over all possible combinations of K query results without repetition. This can only be called for read-only queries.

For permutations of size K of query returning N results, you will get:

  • if K == N: one permutation of all query results
  • if K < N: all possible K-sized combinations of query results, without repetition
  • if K > N: empty set (no K-sized combinations exist)

This can only be called for read-only queries, see Self::iter_combinations_mut for write-queries.

Source

pub fn iter_combinations<'w, 's, const K: usize>( &'s mut self, world: &'w World, ) -> QueryCombinationIter<'w, 's, Q, <Q as WorldQuery>::ReadOnlyFetch, F, K>

Returns an Iterator over all possible combinations of K query results without repetition. This can only be called for read-only queries.

For permutations of size K of query returning N results, you will get:

  • if K == N: one permutation of all query results
  • if K < N: all possible K-sized combinations of query results, without repetition
  • if K > N: empty set (no K-sized combinations exist)

This can only be called for read-only queries, see Self::iter_combinations_mut for write-queries.

Source

pub fn iter_combinations_mut<'w, 's, const K: usize>( &'s mut self, world: &'w mut World, ) -> QueryCombinationIter<'w, 's, Q, <Q as WorldQuery>::Fetch, F, K>

Iterates over all possible combinations of K query results for the given World without repetition.

For permutations of size K of query returning N results, you will get:

  • if K == N: one permutation of all query results
  • if K < N: all possible K-sized combinations of query results, without repetition
  • if K > N: empty set (no K-sized combinations exist)
Source

pub unsafe fn iter_unchecked<'w, 's>( &'s mut self, world: &'w World, ) -> QueryIter<'w, 's, Q, <Q as WorldQuery>::Fetch, F>

Returns an Iterator over the query results for the given World.

§Safety

This does not check for mutable query correctness. To be safe, make sure mutable queries have unique access to the components they query.

Source

pub unsafe fn iter_combinations_unchecked<'w, 's, const K: usize>( &'s mut self, world: &'w World, ) -> QueryCombinationIter<'w, 's, Q, <Q as WorldQuery>::Fetch, F, K>

Returns an Iterator over all possible combinations of K query results for the given World without repetition. This can only be called for read-only queries.

§Safety

This does not check for mutable query correctness. To be safe, make sure mutable queries have unique access to the components they query.

Source

pub fn for_each<'w, 's, FN>(&'s mut self, world: &'w World, func: FN)
where FN: FnMut(<<Q as WorldQuery>::ReadOnlyFetch as Fetch<'w, 's>>::Item),

Runs func on each query result for the given World. This is faster than the equivalent iter() method, but cannot be chained like a normal Iterator.

This can only be called for read-only queries, see Self::for_each_mut for write-queries.

Source

pub fn for_each_mut<'w, 's, FN>(&'s mut self, world: &'w mut World, func: FN)
where FN: FnMut(<<Q as WorldQuery>::Fetch as Fetch<'w, 's>>::Item),

Runs func on each query result for the given World. This is faster than the equivalent iter_mut() method, but cannot be chained like a normal Iterator.

Source

pub unsafe fn for_each_unchecked<'w, 's, FN>( &'s mut self, world: &'w World, func: FN, )
where FN: FnMut(<<Q as WorldQuery>::Fetch as Fetch<'w, 's>>::Item),

Runs func on each query result for the given World. This is faster than the equivalent iter() method, but cannot be chained like a normal Iterator.

This can only be called for read-only queries.

§Safety

This does not check for mutable query correctness. To be safe, make sure mutable queries have unique access to the components they query.

Source

pub fn par_for_each<'w, 's, FN>( &'s mut self, world: &'w World, task_pool: &TaskPool, batch_size: usize, func: FN, )
where FN: Fn(<<Q as WorldQuery>::ReadOnlyFetch as Fetch<'w, 's>>::Item) + Send + Sync + Clone,

Runs func on each query result in parallel using the given task_pool.

This can only be called for read-only queries, see Self::par_for_each_mut for write-queries.

Source

pub fn par_for_each_mut<'w, 's, FN>( &'s mut self, world: &'w mut World, task_pool: &TaskPool, batch_size: usize, func: FN, )
where FN: Fn(<<Q as WorldQuery>::Fetch as Fetch<'w, 's>>::Item) + Send + Sync + Clone,

Runs func on each query result in parallel using the given task_pool.

Source

pub unsafe fn par_for_each_unchecked<'w, 's, FN>( &'s mut self, world: &'w World, task_pool: &TaskPool, batch_size: usize, func: FN, )
where FN: Fn(<<Q as WorldQuery>::Fetch as Fetch<'w, 's>>::Item) + Send + Sync + Clone,

Runs func on each query result in parallel using the given task_pool.

This can only be called for read-only queries.

§Safety

This does not check for mutable query correctness. To be safe, make sure mutable queries have unique access to the components they query.

Trait Implementations§

Source§

impl<'w, 's, Q, F> SystemParamFetch<'w, 's> for QueryState<Q, F>
where Q: WorldQuery + 'static, F: WorldQuery + 'static, <F as WorldQuery>::Fetch: FilterFetch,

Source§

type Item = Query<'w, 's, Q, F>

Source§

unsafe fn get_param( state: &'s mut QueryState<Q, F>, system_meta: &SystemMeta, world: &'w World, change_tick: u32, ) -> <QueryState<Q, F> as SystemParamFetch<'w, 's>>::Item

Safety Read more
Source§

impl<Q, F> SystemParamState for QueryState<Q, F>
where Q: WorldQuery + 'static, F: WorldQuery + 'static, <F as WorldQuery>::Fetch: FilterFetch,

Source§

type Config = ()

Values of this type can be used to adjust the behavior of the system parameter. For instance, this can be used to pass values from a Plugin to a System, or to control the behavior of the System. Read more
Source§

fn init( world: &mut World, system_meta: &mut SystemMeta, _config: <QueryState<Q, F> as SystemParamState>::Config, ) -> QueryState<Q, F>

Source§

fn new_archetype(&mut self, archetype: &Archetype, system_meta: &mut SystemMeta)

Source§

fn default_config()

Source§

fn apply(&mut self, _world: &mut World)

Source§

impl<Q, F> ReadOnlySystemParamFetch for QueryState<Q, F>

Auto Trait Implementations§

§

impl<Q, F> Freeze for QueryState<Q, F>
where <F as WorldQuery>::Fetch: for<'w, 's> Sized, <Q as WorldQuery>::State: Freeze, <F as WorldQuery>::State: Freeze,

§

impl<Q, F> RefUnwindSafe for QueryState<Q, F>
where <F as WorldQuery>::Fetch: for<'w, 's> Sized, <Q as WorldQuery>::State: RefUnwindSafe, <F as WorldQuery>::State: RefUnwindSafe,

§

impl<Q, F> Send for QueryState<Q, F>
where <F as WorldQuery>::Fetch: for<'w, 's> Sized,

§

impl<Q, F> Sync for QueryState<Q, F>
where <F as WorldQuery>::Fetch: for<'w, 's> Sized,

§

impl<Q, F> Unpin for QueryState<Q, F>
where <F as WorldQuery>::Fetch: for<'w, 's> Sized, <Q as WorldQuery>::State: Unpin, <F as WorldQuery>::State: Unpin,

§

impl<Q, F> UnwindSafe for QueryState<Q, F>
where <F as WorldQuery>::Fetch: for<'w, 's> Sized, <Q as WorldQuery>::State: UnwindSafe, <F as WorldQuery>::State: UnwindSafe,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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

impl<T> Resource for T
where T: Send + Sync + 'static,