Struct Query

Source
pub struct Query<V, F = <<V as IntoView>::View as DefaultFilter>::Filter>
where V: IntoView, F: EntityFilter,
{ /* private fields */ }
Expand description

Provides efficient means to iterate and filter entities in a world.

See the module-level documentation for more details and examples.

Implementations§

Source§

impl<V, F> Query<V, F>
where V: IntoView, F: EntityFilter,

Source

pub fn new() -> Query<V, F>

Consructs a new Query

Source

pub fn filter<T>(self, filter: T) -> Query<V, <F as BitAnd<T>>::Output>
where T: EntityFilter, F: BitAnd<T>, <F as BitAnd<T>>::Output: EntityFilter,

Adds an additional filter to the query.

Source

pub unsafe fn get_unchecked<'query, 'world, T>( &'query mut self, world: &'world T, entity: Entity, ) -> Result<<<V as IntoView>::View as View<'world>>::Element, EntityAccessError>
where T: EntityStore,

Returns the components for a single entity.

This function will not evaluate the query’s dynamic filters. This means, for example, that calling get on all entities in an archetype will not prevent maybe_changed from returning those entities the next time the query is iterated.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub fn get_mut<'query, 'world, T>( &'query mut self, world: &'world mut T, entity: Entity, ) -> Result<<<V as IntoView>::View as View<'world>>::Element, EntityAccessError>
where T: EntityStore,

Returns the components for a single entity.

Source

pub fn get<'query, 'world, T>( &'query mut self, world: &'world T, entity: Entity, ) -> Result<<<V as IntoView>::View as View<'world>>::Element, EntityAccessError>
where T: EntityStore, <<V as IntoView>::View as View<'world>>::Fetch: ReadOnlyFetch,

Returns the components for a single entity.

Source

pub unsafe fn iter_chunks_unchecked<'query, 'world, T>( &'query mut self, world: &'world T, ) -> ChunkIter<'world, 'query, <V as IntoView>::View, F>
where T: EntityStore,

Returns an iterator which will yield all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub unsafe fn par_iter_chunks_unchecked<'a, T>( &'a mut self, world: &'a T, ) -> ParChunkIter<'a, <V as IntoView>::View, F>
where T: EntityStore,

Returns a parallel iterator which will yield all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub fn iter_chunks_mut<'query, 'world, T>( &'query mut self, world: &'world mut T, ) -> ChunkIter<'world, 'query, <V as IntoView>::View, F>
where T: EntityStore,

Returns an iterator which will yield all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.

Source

pub fn par_iter_chunks_mut<'a, T>( &'a mut self, world: &'a mut T, ) -> ParChunkIter<'a, <V as IntoView>::View, F>
where T: EntityStore,

Returns a parallel iterator which will yield all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.

Source

pub fn iter_chunks<'query, 'world, T>( &'query mut self, world: &'world T, ) -> ChunkIter<'world, 'query, <V as IntoView>::View, F>
where T: EntityStore, <<V as IntoView>::View as View<'world>>::Fetch: ReadOnlyFetch,

Returns an iterator which will yield all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.
Only usable with queries whose views are read-only.

Source

pub fn par_iter_chunks<'a, T>( &'a mut self, world: &'a T, ) -> ParChunkIter<'a, <V as IntoView>::View, F>
where T: EntityStore, <<V as IntoView>::View as View<'a>>::Fetch: ReadOnlyFetch,

Returns a parallel iterator which will yield all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout. Only usable with queries whose views are read-only.

Source

pub unsafe fn iter_unchecked<'query, 'world, T>( &'query mut self, world: &'world T, ) -> Flatten<ChunkIter<'world, 'query, <V as IntoView>::View, F>>
where T: EntityStore,

Returns an iterator which will yield all components which match the query.

Prefer for_each_unchecked as it offers better performance.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub unsafe fn par_iter_unchecked<'a, T>( &'a mut self, world: &'a T, ) -> Flatten<ParChunkIter<'a, <V as IntoView>::View, F>>
where T: EntityStore,

Returns a parallel iterator which will yield all components which match the query.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub fn iter_mut<'query, 'world, T>( &'query mut self, world: &'world mut T, ) -> Flatten<ChunkIter<'world, 'query, <V as IntoView>::View, F>>
where T: EntityStore,

Returns an iterator which will yield all components which match the query.

Prefer for_each_mut as it yields better performance.

Source

pub fn par_iter_mut<'a, T>( &'a mut self, world: &'a mut T, ) -> Flatten<ParChunkIter<'a, <V as IntoView>::View, F>>
where T: EntityStore,

Returns a parallel iterator which will yield all components which match the query.

Source

pub fn iter<'query, 'world, T>( &'query mut self, world: &'world T, ) -> Flatten<ChunkIter<'world, 'query, <V as IntoView>::View, F>>
where T: EntityStore, <<V as IntoView>::View as View<'world>>::Fetch: ReadOnlyFetch,

Returns an iterator which will yield all components which match the query.

Prefer for_each as it yields better performance.
Only usable with queries whose views are read-only.

Source

pub fn par_iter<'a, T>( &'a mut self, world: &'a T, ) -> Flatten<ParChunkIter<'a, <V as IntoView>::View, F>>
where T: EntityStore, <<V as IntoView>::View as View<'a>>::Fetch: ReadOnlyFetch,

Returns a parallel iterator which will yield all components which match the query.

Only usable with queries whose views are read-only.

Source

pub unsafe fn for_each_chunk_unchecked<'query, 'world, T, Body>( &'query mut self, world: &'world T, f: Body, )
where T: EntityStore, Body: FnMut(ChunkView<'_, <<V as IntoView>::View as View<'world>>::Fetch>),

Iterates through all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub unsafe fn par_for_each_chunk_unchecked<'a, T, Body>( &'a mut self, world: &'a T, f: Body, )
where T: EntityStore, Body: Fn(ChunkView<'_, <<V as IntoView>::View as View<'a>>::Fetch>) + Send + Sync,

Iterates in parallel through all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub fn for_each_chunk_mut<'query, 'world, T, Body>( &'query mut self, world: &'world mut T, f: Body, )
where T: EntityStore, Body: FnMut(ChunkView<'_, <<V as IntoView>::View as View<'world>>::Fetch>),

Iterates through all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.

Source

pub fn par_for_each_chunk_mut<'a, T, Body>( &'a mut self, world: &'a mut T, f: Body, )
where T: EntityStore, Body: Fn(ChunkView<'_, <<V as IntoView>::View as View<'a>>::Fetch>) + Send + Sync,

Iterates in parallel through all entity chunks which match the query.
Each chunk contains slices of components for entities which all have the same component layout.

Source

pub fn for_each_chunk<'query, 'world, T, Body>( &'query mut self, world: &'world T, f: Body, )
where T: EntityStore, Body: FnMut(ChunkView<'_, <<V as IntoView>::View as View<'world>>::Fetch>), <<V as IntoView>::View as View<'world>>::Fetch: ReadOnlyFetch,

Iterates through all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.
Only usable with queries whose views are read-only.

Source

pub fn par_for_each_chunk<'a, T, Body>(&'a mut self, world: &'a T, f: Body)
where T: EntityStore, Body: Fn(ChunkView<'_, <<V as IntoView>::View as View<'a>>::Fetch>) + Send + Sync, <<V as IntoView>::View as View<'a>>::Fetch: ReadOnlyFetch,

Iterates in parallel through all entity chunks which match the query.

Each chunk contains slices of components for entities which all have the same component layout.
Only usable with queries whose views are read-only.

Source

pub unsafe fn for_each_unchecked<'query, 'world, T, Body>( &'query mut self, world: &'world T, f: Body, )
where T: EntityStore, Body: FnMut(<<V as IntoView>::View as View<'world>>::Element),

Iterates through all components which match the query.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub unsafe fn par_for_each_unchecked<'a, T, Body>( &'a mut self, world: &'a T, f: Body, )
where T: EntityStore, Body: Fn(<<V as IntoView>::View as View<'a>>::Element) + Send + Sync,

Iterates in parallel through all components which match the query.

§Safety

This function allows mutable access via a shared world reference. The caller is responsible for ensuring that no component accesses may create mutable aliases.

Source

pub fn for_each_mut<'query, 'world, T, Body>( &'query mut self, world: &'world mut T, f: Body, )
where T: EntityStore, Body: FnMut(<<V as IntoView>::View as View<'world>>::Element),

Iterates through all components which match the query.

Source

pub fn par_for_each_mut<'a, T, Body>(&'a mut self, world: &'a mut T, f: Body)
where T: EntityStore, Body: Fn(<<V as IntoView>::View as View<'a>>::Element) + Send + Sync,

Iterates in parallel through all components which match the query.

Source

pub fn for_each<'query, 'world, T, Body>( &'query mut self, world: &'world T, f: Body, )
where T: EntityStore, Body: FnMut(<<V as IntoView>::View as View<'world>>::Element), <<V as IntoView>::View as View<'world>>::Fetch: ReadOnlyFetch,

Iterates through all components which match the query.

Only usable with queries whose views are read-only.

Source

pub fn par_for_each<'a, T, Body>(&'a mut self, world: &'a T, f: Body)
where T: EntityStore, Body: Fn(<<V as IntoView>::View as View<'a>>::Element) + Send + Sync, <<V as IntoView>::View as View<'a>>::Fetch: ReadOnlyFetch,

Iterates in parallel through all components which match the query.

Only usable with queries whose views are read-only.

Trait Implementations§

Source§

impl<V, F> Default for Query<V, F>
where V: IntoView, F: EntityFilter,

Source§

fn default() -> Query<V, F>

Returns the “default value” for a type. Read more
Source§

impl<AV, AF> QuerySet for Query<AV, AF>
where AV: IntoView + Send + Sync, AF: EntityFilter,

Source§

fn filter_archetypes(&mut self, world: &World, bitset: &mut BitSet)

Evaluates the queries and records which archetypes they require access to into a bitset.

Auto Trait Implementations§

§

impl<V, F = <<V as IntoView>::View as DefaultFilter>::Filter> !Freeze for Query<V, F>

§

impl<V, F = <<V as IntoView>::View as DefaultFilter>::Filter> !RefUnwindSafe for Query<V, F>

§

impl<V, F> Send for Query<V, F>
where V: Send,

§

impl<V, F> Sync for Query<V, F>
where V: Sync,

§

impl<V, F> Unpin for Query<V, F>
where V: Unpin, F: Unpin,

§

impl<V, F> UnwindSafe for Query<V, F>
where V: UnwindSafe, F: 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> Component for T
where T: 'static + Send + Sync,

Source§

type Storage = PackedStorage<T>

The storage type required to hold all instances of this component in a world.
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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> Resource for T
where T: 'static,