[][src]Struct hecs::QueryBorrow

pub struct QueryBorrow<'w, Q: Query> { /* fields omitted */ }

A borrow of a World sufficient to execute the query Q

Note that borrows are not released until this object is dropped.

Implementations

impl<'w, Q: Query> QueryBorrow<'w, Q>[src]

pub fn iter<'q>(&'q mut self) -> QueryIter<'q, 'w, Q>

Important traits for QueryIter<'q, 'w, Q>

impl<'q, 'w, Q: Query> Iterator for QueryIter<'q, 'w, Q> type Item = (Entity, <Q::Fetch as Fetch<'q>>::Item);
[src]

Execute the query

Must be called only once per query.

pub fn iter_batched<'q>(&'q mut self, batch_size: u32) -> BatchedIter<'q, 'w, Q>

Important traits for BatchedIter<'q, 'w, Q>

impl<'q, 'w, Q: Query> Iterator for BatchedIter<'q, 'w, Q> type Item = Batch<'q, 'w, Q>;
[src]

Like iter, but returns child iterators of at most batch_size elements

Useful for distributing work over a threadpool.

pub fn with<T: Component>(self) -> QueryBorrow<'w, With<T, Q>>[src]

Transform the query into one that requires a certain component without borrowing it

This can be useful when the component needs to be borrowed elsewhere and it isn't necessary for the iterator to expose its data directly.

Equivalent to using a query type wrapped in With.

Example

let mut world = World::new();
let a = world.spawn((123, true, "abc"));
let b = world.spawn((456, false));
let c = world.spawn((42, "def"));
let entities = world.query::<&i32>()
    .with::<bool>()
    .iter()
    .map(|(e, &i)| (e, i)) // Copy out of the world
    .collect::<Vec<_>>();
assert!(entities.contains(&(a, 123)));
assert!(entities.contains(&(b, 456)));

pub fn without<T: Component>(self) -> QueryBorrow<'w, Without<T, Q>>[src]

Transform the query into one that skips entities having a certain component

Equivalent to using a query type wrapped in Without.

Example

let mut world = World::new();
let a = world.spawn((123, true, "abc"));
let b = world.spawn((456, false));
let c = world.spawn((42, "def"));
let entities = world.query::<&i32>()
    .without::<bool>()
    .iter()
    .map(|(e, &i)| (e, i)) // Copy out of the world
    .collect::<Vec<_>>();
assert_eq!(entities, &[(c, 42)]);

Trait Implementations

impl<'w, Q: Query> Drop for QueryBorrow<'w, Q>[src]

impl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q>[src]

type Item = (Entity, <Q::Fetch as Fetch<'q>>::Item)

The type of the elements being iterated over.

type IntoIter = QueryIter<'q, 'w, Q>

Which kind of iterator are we turning this into?

impl<'w, Q: Query> Send for QueryBorrow<'w, Q>[src]

impl<'w, Q: Query> Sync for QueryBorrow<'w, Q>[src]

Auto Trait Implementations

impl<'w, Q> !RefUnwindSafe for QueryBorrow<'w, Q>

impl<'w, Q> Unpin for QueryBorrow<'w, Q> where
    Q: Unpin

impl<'w, Q> !UnwindSafe for QueryBorrow<'w, Q>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.