Query

Struct Query 

Source
pub struct Query<I, C> { /* private fields */ }
Expand description

An iterator to find entities that share components.

It creates an intersection of ComponentVecs and yields the entities as well as their components.

The struct is created by calling the into_query method on tuples of ComponentVecs.

§Examples

use checs::{ComponentVec, IntoQuery, LendingIterator};
use checs::entity::Allocator;

let mut entities = Allocator::new();
let e0 = entities.alloc();
let e1 = entities.alloc();
let e2 = entities.alloc();
let e3 = entities.alloc();
let e4 = entities.alloc();

let mut strs = ComponentVec::new();
strs.insert(e0, "ninety-nine");
strs.insert(e1, "zero");
strs.insert(e2, "forty-two");
strs.insert(e4, "seventeen");

let mut ints = ComponentVec::new();
ints.insert(e0, 99);
ints.insert(e2, 42);
ints.insert(e3, 1);
ints.insert(e4, 17);

let mut query = (&strs, &mut ints).into_query();

assert_eq!(query.next(), Some((e0, (&"ninety-nine", &mut 99))));
assert_eq!(query.next(), Some((e2, (&"forty-two", &mut 42))));
assert_eq!(query.next(), Some((e4, (&"seventeen", &mut 17))));
assert_eq!(query.next(), None);

Note: In the above example entities e1 and e3 each only have one of the components not both, so they are not included in the query.

Trait Implementations§

Source§

impl<Iter, C> LendingIterator for Query<Iter, C>
where Iter: Iterator<Item = Entity>, C: GetRefOrMut,

Source§

fn next(&mut self) -> Option<<Self as Lifetime<'_>>::Item>

Advances the iterator and returns the next value. Read more
Source§

fn for_each<F>(self, f: F)
where Self: Sized, F: FnMut(<Self as Lifetime<'_>>::Item),

Calls a closure on each element of the iterator. Read more
Source§

impl<'l, Iter, C> Lifetime<'l> for Query<Iter, C>
where Iter: Iterator<Item = Entity>, C: Lifetime<'l>,

Source§

type Item = (Entity, <C as Lifetime<'l>>::Item)

The type of the elements being iterated over.

Auto Trait Implementations§

§

impl<I, C> Freeze for Query<I, C>
where I: Freeze, C: Freeze,

§

impl<I, C> RefUnwindSafe for Query<I, C>

§

impl<I, C> Send for Query<I, C>
where I: Send, C: Send,

§

impl<I, C> Sync for Query<I, C>
where I: Sync, C: Sync,

§

impl<I, C> Unpin for Query<I, C>
where I: Unpin, C: Unpin,

§

impl<I, C> UnwindSafe for Query<I, C>
where I: UnwindSafe, C: 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> 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, 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.