Skip to main content

NameOrEntity

Struct NameOrEntity 

pub struct NameOrEntity {
    pub name: Option<&'static Name>,
    pub entity: Entity,
}
Expand description

Convenient query for giving a human friendly name to an entity.

fn increment_score(mut scores: Query<(NameOrEntity, &mut Score)>) {
    for (name, mut score) in &mut scores {
        score.0 += 1.0;
        if score.0.is_nan() {
            log::error!("Score for {name} is invalid");
        }
    }
}

§Implementation

The Display impl for NameOrEntity returns the Name where there is one or {index}v{generation} for entities without one.

Fields§

§name: Option<&'static Name>

A Name that the entity might have that is displayed if available.

§entity: Entity

The unique identifier of the entity as a fallback.

Trait Implementations§

§

impl QueryData for NameOrEntity

§

unsafe fn fetch<'__w, '__s>( _state: &'__s <NameOrEntity as WorldQuery>::State, _fetch: &mut <NameOrEntity as WorldQuery>::Fetch<'__w>, _entity: Entity, _table_row: TableRow, ) -> Option<<NameOrEntity as QueryData>::Item<'__w, '__s>>

SAFETY: we call fetch for each member that implements Fetch.

§

const IS_READ_ONLY: bool = true

True if this query is read-only and may not perform mutable access.
§

const IS_ARCHETYPAL: bool

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

type ReadOnly = NameOrEntity

The read-only variant of this [QueryData], which satisfies the [ReadOnlyQueryData] trait.
§

type Item<'__w, '__s> = NameOrEntityItem<'__w, '__s>

The item returned by this [WorldQuery] This will be the data retrieved by the query, and is visible to the end user when calling e.g. Query<Self>::get.
§

fn shrink<'__wlong, '__wshort, '__s>( item: <NameOrEntity as QueryData>::Item<'__wlong, '__s>, ) -> <NameOrEntity as QueryData>::Item<'__wshort, '__s>
where '__wlong: '__wshort,

This function manually implements subtyping for the query items.
§

fn provide_extra_access( state: &mut <NameOrEntity as WorldQuery>::State, access: &mut Access, available_access: &Access, )

Offers additional access above what we requested in update_component_access. Implementations may add additional access that is a subset of available_access and does not conflict with anything in access, and must update access to include that access. Read more
§

fn iter_access( _state: &<NameOrEntity as WorldQuery>::State, ) -> impl Iterator<Item = EcsAccessType<'_>>

Returns an iterator over the access needed by [QueryData::fetch]. Access conflicts are usually checked in [WorldQuery::update_component_access], but in certain cases this method can be useful to implement a way of checking for access conflicts in a non-allocating way.
§

impl ReleaseStateQueryData for NameOrEntity
where Option<&'static Name>: for<'__a> ReleaseStateQueryData, Entity: for<'__a> ReleaseStateQueryData,

§

fn release_state<'__w>( _item: <NameOrEntity as QueryData>::Item<'__w, '_>, ) -> <NameOrEntity as QueryData>::Item<'__w, 'static>

Releases the borrow from the query state by converting an item to have a 'static state lifetime.
§

impl WorldQuery for NameOrEntity

§

unsafe fn set_archetype<'__w, '__s>( _fetch: &mut <NameOrEntity as WorldQuery>::Fetch<'__w>, _state: &'__s <NameOrEntity as WorldQuery>::State, _archetype: &'__w Archetype, _table: &'__w Table, )

SAFETY: we call set_archetype for each member that implements Fetch

§

unsafe fn set_table<'__w, '__s>( _fetch: &mut <NameOrEntity as WorldQuery>::Fetch<'__w>, _state: &'__s <NameOrEntity as WorldQuery>::State, _table: &'__w Table, )

SAFETY: we call set_table for each member that implements Fetch

§

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> = NameOrEntityFetch<'__w>

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

type State = NameOrEntityState

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>( fetch: <NameOrEntity as WorldQuery>::Fetch<'__wlong>, ) -> <NameOrEntity as WorldQuery>::Fetch<'__wshort>
where '__wlong: '__wshort,

This function manually implements subtyping for the query fetches.
§

unsafe fn init_fetch<'__w, '__s>( _world: UnsafeWorldCell<'__w>, state: &'__s <NameOrEntity as WorldQuery>::State, _last_run: Tick, _this_run: Tick, ) -> <NameOrEntity as WorldQuery>::Fetch<'__w>

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
§

fn update_component_access( state: &<NameOrEntity as WorldQuery>::State, _access: &mut FilteredAccess, )

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

fn init_nested_access( state: &<NameOrEntity as WorldQuery>::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 init_state(world: &mut World) -> NameOrEntityState

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

fn get_state(components: &Components) -> Option<NameOrEntityState>

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

fn matches_component_set( state: &<NameOrEntity as WorldQuery>::State, _set_contains_id: &impl Fn(ComponentId) -> bool, ) -> bool

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

fn update_archetypes( _state: &mut <NameOrEntity as WorldQuery>::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 ArchetypeQueryData for NameOrEntity
where Option<&'static Name>: for<'__a> ArchetypeQueryData, Entity: for<'__a> ArchetypeQueryData,

§

impl IterQueryData for NameOrEntity
where Option<&'static Name>: for<'__a> IterQueryData, Entity: for<'__a> IterQueryData,

§

impl ReadOnlyQueryData for NameOrEntity

§

impl SingleEntityQueryData for NameOrEntity
where Option<&'static Name>: for<'__a> SingleEntityQueryData, Entity: for<'__a> SingleEntityQueryData,

Auto Trait Implementations§

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,