Struct oxygengine_core::ecs::QueryBorrow [−][src]
pub struct QueryBorrow<'w, Q> where
Q: Query, { /* fields omitted */ }
Expand description
A borrow of a World
sufficient to execute the query Q
Note that borrows are not released until this object is dropped.
Implementations
Execute the query
pub fn iter_batched(&mut self, batch_size: u32) -> BatchedIter<'_, Q>ⓘNotable traits for BatchedIter<'q, Q>impl<'q, Q> Iterator for BatchedIter<'q, Q> where
Q: Query, type Item = Batch<'q, Q>;
pub fn iter_batched(&mut self, batch_size: u32) -> BatchedIter<'_, Q>ⓘNotable traits for BatchedIter<'q, Q>impl<'q, Q> Iterator for BatchedIter<'q, Q> where
Q: Query, type Item = Batch<'q, Q>;
Notable traits for BatchedIter<'q, Q>
impl<'q, Q> Iterator for BatchedIter<'q, Q> where
Q: Query, type Item = Batch<'q, Q>;
Like iter
, but returns child iterators of at most batch_size
elements
Useful for distributing work over a threadpool.
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)));
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
The type of the elements being iterated over.
Creates an iterator from a value. Read more