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
e1ande3each 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>
impl<Iter, C> LendingIterator for Query<Iter, C>
Auto Trait Implementations§
impl<I, C> Freeze for Query<I, C>
impl<I, C> RefUnwindSafe for Query<I, C>where
I: RefUnwindSafe,
C: RefUnwindSafe,
impl<I, C> Send for Query<I, C>
impl<I, C> Sync for Query<I, C>
impl<I, C> Unpin for Query<I, C>
impl<I, C> UnwindSafe for Query<I, C>where
I: UnwindSafe,
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more