Skip to main content

QueryBorrow

Struct QueryBorrow 

Source
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, ()>

Source

pub(crate) fn new( world: &'w World, scope: Entity, origin: &'static Location<'static>, ) -> Self

Source§

impl<'w, Q: Query, F: ArchetypeFilter> QueryBorrow<'w, Q, F>

Source

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.

Source

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

Iterate the visible entities that match Q.

The items borrow from this holder, so they cannot outlive it and it cannot be iterated for one item at a time while another is alive: collect them, or finish with each row before reaching for the next.

Trait Implementations§

Source§

impl<Q: Query, F: ArchetypeFilter> Debug for QueryBorrow<'_, Q, F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'w, Q, F = ()> !RefUnwindSafe for QueryBorrow<'w, Q, F>

§

impl<'w, Q, F = ()> !Send for QueryBorrow<'w, Q, F>

§

impl<'w, Q, F = ()> !Sync for QueryBorrow<'w, Q, F>

§

impl<'w, Q, F = ()> !UnwindSafe for QueryBorrow<'w, Q, F>

§

impl<'w, Q, F> Forget for QueryBorrow<'w, Q, F>

§

impl<'w, Q, F> Freeze for QueryBorrow<'w, Q, F>
where F: Freeze, PhantomData<fn() -> Q>: Freeze,

§

impl<'w, Q, F> Unpin for QueryBorrow<'w, Q, F>
where F: Unpin, PhantomData<fn() -> Q>: Unpin,

§

impl<'w, Q, F> UnsafeUnpin for QueryBorrow<'w, Q, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Component for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more