Struct hecs::QueryBorrow
source · [−]pub struct QueryBorrow<'w, Q: Query> { /* private fields */ }
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
sourceimpl<'w, Q: Query> QueryBorrow<'w, Q>
impl<'w, Q: Query> QueryBorrow<'w, Q>
sourcepub fn iter(&mut self) -> QueryIter<'_, Q>ⓘNotable traits for QueryIter<'q, Q>impl<'q, Q: Query> Iterator for QueryIter<'q, Q> type Item = (Entity, QueryItem<'q, Q>);
pub fn iter(&mut self) -> QueryIter<'_, Q>ⓘNotable traits for QueryIter<'q, Q>impl<'q, Q: Query> Iterator for QueryIter<'q, Q> type Item = (Entity, QueryItem<'q, Q>);
Execute the query
sourcepub fn iter_batched(&mut self, batch_size: u32) -> BatchedIter<'_, Q>ⓘNotable traits for BatchedIter<'q, Q>impl<'q, Q: Query> Iterator for BatchedIter<'q, Q> 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: Query> Iterator for BatchedIter<'q, Q> type Item = Batch<'q, Q>;
Like iter
, but returns child iterators of at most batch_size
elements
Useful for distributing work over a threadpool.
sourcepub fn with<T: Component>(self) -> QueryBorrow<'w, With<T, Q>>
pub fn with<T: Component>(self) -> QueryBorrow<'w, With<T, Q>>
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)));
sourcepub fn without<T: Component>(self) -> QueryBorrow<'w, Without<T, Q>>
pub fn without<T: Component>(self) -> QueryBorrow<'w, Without<T, Q>>
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
sourceimpl<'w, Q: Query> Drop for QueryBorrow<'w, Q>
impl<'w, Q: Query> Drop for QueryBorrow<'w, Q>
sourceimpl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q>
impl<'q, 'w, Q: Query> IntoIterator for &'q mut QueryBorrow<'w, Q>
impl<'w, Q: Query> Send for QueryBorrow<'w, Q>
impl<'w, Q: Query> Sync for QueryBorrow<'w, Q>
Auto Trait Implementations
impl<'w, Q> RefUnwindSafe for QueryBorrow<'w, Q> where
Q: RefUnwindSafe,
impl<'w, Q> Unpin for QueryBorrow<'w, Q> where
Q: Unpin,
impl<'w, Q> UnwindSafe for QueryBorrow<'w, Q> where
Q: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more