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: EntityThe unique identifier of the entity as a fallback.
Trait Implementations§
§impl QueryData for NameOrEntity
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>>
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
const IS_READ_ONLY: bool = true
True if this query is read-only and may not perform mutable access.
§const IS_ARCHETYPAL: bool
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
type ReadOnly = NameOrEntity
The read-only variant of this [
QueryData], which satisfies the [ReadOnlyQueryData] trait.§type Item<'__w, '__s> = NameOrEntityItem<'__w, '__s>
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,
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,
)
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<'_>>
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
impl ReleaseStateQueryData for NameOrEntity
§fn release_state<'__w>(
_item: <NameOrEntity as QueryData>::Item<'__w, '_>,
) -> <NameOrEntity as QueryData>::Item<'__w, 'static>
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
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,
)
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,
)
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
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>
type Fetch<'__w> = NameOrEntityFetch<'__w>
Per archetype/table state retrieved by this [
WorldQuery] to compute Self::Item for each entity.§type State = NameOrEntityState
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,
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>
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,
)
fn update_component_access( state: &<NameOrEntity as WorldQuery>::State, _access: &mut FilteredAccess, )
§fn init_nested_access(
state: &<NameOrEntity as WorldQuery>::State,
_system_name: Option<&str>,
_component_access_set: &mut FilteredAccessSet,
_world: UnsafeWorldCell<'_>,
)
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
fn init_state(world: &mut World) -> NameOrEntityState
Creates and initializes a
State for this [WorldQuery] type.§fn matches_component_set(
state: &<NameOrEntity as WorldQuery>::State,
_set_contains_id: &impl Fn(ComponentId) -> bool,
) -> bool
fn matches_component_set( state: &<NameOrEntity as WorldQuery>::State, _set_contains_id: &impl Fn(ComponentId) -> bool, ) -> bool
§fn update_archetypes(
_state: &mut <NameOrEntity as WorldQuery>::State,
_world: UnsafeWorldCell<'_>,
)
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
impl IterQueryData for NameOrEntity
impl ReadOnlyQueryData for NameOrEntity
impl SingleEntityQueryData for NameOrEntity
Auto Trait Implementations§
impl Freeze for NameOrEntity
impl RefUnwindSafe for NameOrEntity
impl Send for NameOrEntity
impl Sync for NameOrEntity
impl Unpin for NameOrEntity
impl UnsafeUnpin for NameOrEntity
impl UnwindSafe for NameOrEntity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
Converts this type into the system output type.