Skip to main content

With

Struct With 

pub struct With<T>(/* private fields */);
Expand description

Filter that selects entities with a component T.

This can be used in a Query if entities are required to have the component T but you don’t actually care about components value.

This is the negation of Without.

§Examples

fn compliment_entity_system(query: Query<&Name, With<IsBeautiful>>) {
    for name in &query {
        println!("{} is looking lovely today!", name.name);
    }
}

Trait Implementations§

§

impl<T> QueryFilter for With<T>
where T: Component,

§

const IS_ARCHETYPAL: bool = true

Returns true if (and only if) this Filter relies strictly on archetypes to limit which components are accessed by the Query. Read more
§

unsafe fn filter_fetch( _state: &<With<T> as WorldQuery>::State, _fetch: &mut <With<T> as WorldQuery>::Fetch<'_>, _entity: Entity, _table_row: TableRow, ) -> bool

Returns true if the provided Entity and [TableRow] should be included in the query results. If false, the entity will be skipped. Read more
§

impl<T> WorldQuery for With<T>
where T: Component,

§

const IS_DENSE: bool

Returns true if (and only if) every table of every archetype matched by this fetch contains all of the matched components. Read more
§

type Fetch<'w> = ()

Per archetype/table state retrieved by this [WorldQuery] to compute Self::Item for each entity.
§

type State = ComponentId

State used to construct a Self::Fetch. This will be cached inside QueryState, so it is best to move as much data / computation here as possible to reduce the cost of constructing Self::Fetch.
§

fn shrink_fetch<'wlong, 'wshort>( _: <With<T> as WorldQuery>::Fetch<'wlong>, ) -> <With<T> as WorldQuery>::Fetch<'wshort>
where 'wlong: 'wshort,

This function manually implements subtyping for the query fetches.
§

unsafe fn init_fetch( _world: UnsafeWorldCell<'_>, _state: &ComponentId, _last_run: Tick, _this_run: Tick, )

Creates a new instance of Self::Fetch, by combining data from the World with the cached Self::State. Readonly accesses resources registered in [WorldQuery::update_component_access]. Read more
§

unsafe fn set_archetype( _fetch: &mut (), _state: &ComponentId, _archetype: &Archetype, _table: &Table, )

Adjusts internal state to account for the next [Archetype]. This will always be called on archetypes that match this [WorldQuery]. Read more
§

unsafe fn set_table(_fetch: &mut (), _state: &ComponentId, _table: &Table)

Adjusts internal state to account for the next [Table]. This will always be called on tables that match this [WorldQuery]. Read more
§

fn update_component_access(_: &ComponentId, access: &mut FilteredAccess)

Adds any component accesses to the current entity used by this [WorldQuery] to access. Read more
§

fn init_state(world: &mut World) -> ComponentId

Creates and initializes a State for this [WorldQuery] type.
§

fn get_state(components: &Components) -> Option<<With<T> as WorldQuery>::State>

Attempts to initialize a State for this [WorldQuery] type using read-only access to [Components].
§

fn matches_component_set( _: &ComponentId, set_contains_id: &impl Fn(ComponentId) -> bool, ) -> bool

Returns true if this query matches a set of components. Otherwise, returns false. Read more
§

fn init_nested_access( _state: &Self::State, _system_name: Option<&str>, _component_access_set: &mut FilteredAccessSet, _world: UnsafeWorldCell<'_>, )

Adds any component accesses to other entities used by this [WorldQuery]. Read more
§

fn update_archetypes(_state: &mut Self::State, _world: UnsafeWorldCell<'_>)

Called when the query state is updating its archetype cache. This can be used by nested queries to update their internal archetype caches.
§

impl<T> ArchetypeFilter for With<T>
where T: Component,

Auto Trait Implementations§

§

impl<T> Freeze for With<T>

§

impl<T> RefUnwindSafe for With<T>
where T: RefUnwindSafe,

§

impl<T> Send for With<T>
where T: Send,

§

impl<T> Sync for With<T>
where T: Sync,

§

impl<T> Unpin for With<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for With<T>

§

impl<T> UnwindSafe for With<T>
where T: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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> ConditionalSend for T
where T: Send,