pub struct QueryBorrow<'w, Q: Query, F: ArchetypeFilter = ()> {
world: &'w World,
scope: Entity,
filter: F,
claims: Claims<'w>,
asks: Vec<(TypeId, &'static str, Mode)>,
origin: &'static Location<'static>,
marker: PhantomData<fn() -> Q>,
}Expand description
What a scope hands out for a query: the claims, and the way to iterate them.
The holder is created by crate::Scope::query and claims the components
the query reaches, archetype by archetype, before it hands out anything.
Iterating is QueryBorrow::iter, and every item it yields borrows from
this holder, so the claims outlive the items by construction.
Dropping the holder releases the claims. Forgetting it instead
(core::mem::forget) leaks them: the components stay claimed for the rest
of the world’s life, and the next query for them panics rather than running
alongside.
Fields§
§world: &'w World§scope: Entity§filter: F§claims: Claims<'w>§asks: Vec<(TypeId, &'static str, Mode)>The buffer a pass over the archetypes records its asks in, kept here so that a second pass reuses it rather than allocating again.
origin: &'static Location<'static>§marker: PhantomData<fn() -> Q>Implementations§
Source§impl<'w, Q: Query> QueryBorrow<'w, Q, ()>
impl<'w, Q: Query> QueryBorrow<'w, Q, ()>
Source§impl<'w, Q: Query, F: ArchetypeFilter> QueryBorrow<'w, Q, F>
impl<'w, Q: Query, F: ArchetypeFilter> QueryBorrow<'w, Q, F>
Sourcepub fn by<G: ArchetypeFilter>(self, filter: G) -> QueryBorrow<'w, Q, G>
pub fn by<G: ArchetypeFilter>(self, filter: G) -> QueryBorrow<'w, Q, G>
Visit only the archetypes the filter accepts.
The filter sees an archetype before any of its rows is fetched and before
any value is reached, so rejecting an archetype costs one test rather than
one per row, and works even when that archetype’s components are already
claimed elsewhere. See ArchetypeFilter.
It may be applied part-way through an iteration, and then narrows the archetype being visited too: what the filter rejects is not fetched, and the rows already yielded stay yielded.