pub unsafe trait DynamicComponentFetch {
type Ref<'w>;
type Mut<'w>;
// Required methods
unsafe fn fetch_ref(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Ref<'_>, EntityComponentError>;
unsafe fn fetch_mut(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Mut<'_>, EntityComponentError>;
unsafe fn fetch_mut_assume_mutable(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Mut<'_>, EntityComponentError>;
}Expand description
Types that can be used to fetch components from an entity dynamically by
ComponentIds.
Provided implementations are:
ComponentId: Returns a single untyped reference.[ComponentId; N]and&[ComponentId; N]: Returns a same-sized array of untyped references.&[ComponentId]: Returns aVecof untyped references.&HashSet<ComponentId>: Returns aHashMapof IDs to untyped references.
§Performance
- The slice and array implementations perform an aliased mutability check in
DynamicComponentFetch::fetch_mutthat isO(N^2). - The
HashSetimplementation performs no such check as the type itself guarantees unique IDs. - The single
ComponentIdimplementation performs no such check as only one reference is returned.
§Safety
Implementor must ensure that:
- No aliased mutability is caused by the returned references.
DynamicComponentFetch::fetch_refreturns only read-only references.
Required Associated Types§
Sourcetype Ref<'w>
type Ref<'w>
The read-only reference type returned by DynamicComponentFetch::fetch_ref.
Sourcetype Mut<'w>
type Mut<'w>
The mutable reference type returned by DynamicComponentFetch::fetch_mut.
Required Methods§
Sourceunsafe fn fetch_ref(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Ref<'_>, EntityComponentError>
unsafe fn fetch_ref( self, cell: UnsafeEntityCell<'_>, ) -> Result<Self::Ref<'_>, EntityComponentError>
Returns untyped read-only reference(s) to the component(s) with the
given ComponentIds, as determined by self.
§Safety
It is the caller’s responsibility to ensure that:
- The given
UnsafeEntityCellhas read-only access to the fetched components. - No other mutable references to the fetched components exist at the same time.
§Errors
- Returns
EntityComponentError::MissingComponentif a component is missing from the entity.
Sourceunsafe fn fetch_mut(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Mut<'_>, EntityComponentError>
unsafe fn fetch_mut( self, cell: UnsafeEntityCell<'_>, ) -> Result<Self::Mut<'_>, EntityComponentError>
Returns untyped mutable reference(s) to the component(s) with the
given ComponentIds, as determined by self.
§Safety
It is the caller’s responsibility to ensure that:
- The given
UnsafeEntityCellhas mutable access to the fetched components. - No other references to the fetched components exist at the same time.
§Errors
- Returns
EntityComponentError::MissingComponentif a component is missing from the entity. - Returns
EntityComponentError::AliasedMutabilityif a component is requested multiple times.
Sourceunsafe fn fetch_mut_assume_mutable(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Mut<'_>, EntityComponentError>
unsafe fn fetch_mut_assume_mutable( self, cell: UnsafeEntityCell<'_>, ) -> Result<Self::Mut<'_>, EntityComponentError>
Returns untyped mutable reference(s) to the component(s) with the
given ComponentIds, as determined by self.
Assumes all ComponentIds refer to mutable components.
§Safety
It is the caller’s responsibility to ensure that:
- The given
UnsafeEntityCellhas mutable access to the fetched components. - No other references to the fetched components exist at the same time.
- The requested components are all mutable.
§Errors
- Returns
EntityComponentError::MissingComponentif a component is missing from the entity. - Returns
EntityComponentError::AliasedMutabilityif a component is requested multiple times.
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.