pub unsafe trait WorldEntityFetch {
type Ref<'w>;
type Mut<'w>;
type DeferredMut<'w>;
// Required methods
unsafe fn fetch_ref(
self,
cell: UnsafeWorldCell<'_>,
) -> Result<Self::Ref<'_>, EntityDoesNotExistError>;
unsafe fn fetch_mut(
self,
cell: UnsafeWorldCell<'_>,
) -> Result<Self::Mut<'_>, EntityMutableFetchError>;
unsafe fn fetch_deferred_mut(
self,
cell: UnsafeWorldCell<'_>,
) -> Result<Self::DeferredMut<'_>, EntityMutableFetchError>;
}Expand description
Types that can be used to fetch Entity references from a World.
Provided implementations are:
Entity: Fetch a single entity.[Entity; N]/&[Entity; N]: Fetch multiple entities, receiving a same-sized array of references.&[Entity]: Fetch multiple entities, receiving a vector of references.&EntityHashSet: Fetch multiple entities, receiving a hash map ofEntityIDs to references.
§Performance
- The slice and array implementations perform an aliased mutability check
in
WorldEntityFetch::fetch_mutthat isO(N^2). - The single
Entityimplementation performs no such check as only one reference is returned.
§Safety
Implementor must ensure that:
- No aliased mutability is caused by the returned references.
WorldEntityFetch::fetch_refreturns only read-only references.WorldEntityFetch::fetch_deferred_mutreturns only non-structurally-mutable references.
Required Associated Types§
Sourcetype Ref<'w>
type Ref<'w>
The read-only reference type returned by WorldEntityFetch::fetch_ref.
Sourcetype Mut<'w>
type Mut<'w>
The mutable reference type returned by WorldEntityFetch::fetch_mut.
Sourcetype DeferredMut<'w>
type DeferredMut<'w>
The mutable reference type returned by WorldEntityFetch::fetch_deferred_mut,
but without structural mutability.
Required Methods§
Sourceunsafe fn fetch_ref(
self,
cell: UnsafeWorldCell<'_>,
) -> Result<Self::Ref<'_>, EntityDoesNotExistError>
unsafe fn fetch_ref( self, cell: UnsafeWorldCell<'_>, ) -> Result<Self::Ref<'_>, EntityDoesNotExistError>
Returns read-only reference(s) to the entities with the given
Entity IDs, as determined by self.
§Safety
It is the caller’s responsibility to ensure that:
- The given
UnsafeWorldCellhas read-only access to the fetched entities. - No other mutable references to the fetched entities exist at the same time.
§Errors
- Returns
EntityDoesNotExistErrorif the entity does not exist.
Sourceunsafe fn fetch_mut(
self,
cell: UnsafeWorldCell<'_>,
) -> Result<Self::Mut<'_>, EntityMutableFetchError>
unsafe fn fetch_mut( self, cell: UnsafeWorldCell<'_>, ) -> Result<Self::Mut<'_>, EntityMutableFetchError>
Returns mutable reference(s) to the entities with the given Entity
IDs, as determined by self.
§Safety
It is the caller’s responsibility to ensure that:
- The given
UnsafeWorldCellhas mutable access to the fetched entities. - No other references to the fetched entities exist at the same time.
§Errors
- Returns
EntityMutableFetchError::EntityDoesNotExistif the entity does not exist. - Returns
EntityMutableFetchError::AliasedMutabilityif the entity was requested mutably more than once.
Sourceunsafe fn fetch_deferred_mut(
self,
cell: UnsafeWorldCell<'_>,
) -> Result<Self::DeferredMut<'_>, EntityMutableFetchError>
unsafe fn fetch_deferred_mut( self, cell: UnsafeWorldCell<'_>, ) -> Result<Self::DeferredMut<'_>, EntityMutableFetchError>
Returns mutable reference(s) to the entities with the given Entity
IDs, as determined by self, but without structural mutability.
No structural mutability means components cannot be removed from the entity, new components cannot be added to the entity, and the entity cannot be despawned.
§Safety
It is the caller’s responsibility to ensure that:
- The given
UnsafeWorldCellhas mutable access to the fetched entities. - No other references to the fetched entities exist at the same time.
§Errors
- Returns
EntityMutableFetchError::EntityDoesNotExistif the entity does not exist. - Returns
EntityMutableFetchError::AliasedMutabilityif the entity was requested mutably more than once.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.