pub struct ComponentId(/* private fields */);Expand description
A value which uniquely identifies the type of a Component or Resource within a
World.
Each time a new Component type is registered within a World using
e.g. World::register_component or
World::register_component_with_descriptor
or a Resource with e.g. World::init_resource,
a corresponding ComponentId is created to track it.
While the distinction between ComponentId and TypeId may seem superficial, breaking them
into two separate but related concepts allows components to exist outside of Rust’s type system.
Each Rust type registered as a Component will have a corresponding ComponentId, but additional
ComponentIds may exist in a World to track components which cannot be
represented as Rust types for scripting or other advanced use-cases.
A ComponentId is tightly coupled to its parent World. Attempting to use a ComponentId from
one World to access the metadata of a Component in a different World is undefined behavior
and must not be attempted.
Given a type T which implements Component, the ComponentId for T can be retrieved
from a World using World::component_id() or via Components::component_id().
Access to the ComponentId for a Resource is available via Components::resource_id().
Implementations§
Source§impl ComponentId
impl ComponentId
Sourcepub const fn new(index: usize) -> ComponentId
pub const fn new(index: usize) -> ComponentId
Creates a new ComponentId.
The index is a unique value associated with each type of component in a given world.
Usually, this value is taken from a counter incremented for each type of component registered with the world.
Trait Implementations§
Source§impl Clone for ComponentId
impl Clone for ComponentId
Source§fn clone(&self) -> ComponentId
fn clone(&self) -> ComponentId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ComponentId
impl Debug for ComponentId
Source§impl DynamicComponentFetch for ComponentId
impl DynamicComponentFetch for ComponentId
Source§type Ref<'w> = Ptr<'w>
type Ref<'w> = Ptr<'w>
DynamicComponentFetch::fetch_ref.Source§type Mut<'w> = MutUntyped<'w>
type Mut<'w> = MutUntyped<'w>
DynamicComponentFetch::fetch_mut.Source§unsafe fn fetch_ref(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Ref<'_>, EntityComponentError>
unsafe fn fetch_ref( self, cell: UnsafeEntityCell<'_>, ) -> Result<Self::Ref<'_>, EntityComponentError>
ComponentIds, as determined by self. Read moreSource§unsafe fn fetch_mut(
self,
cell: UnsafeEntityCell<'_>,
) -> Result<Self::Mut<'_>, EntityComponentError>
unsafe fn fetch_mut( self, cell: UnsafeEntityCell<'_>, ) -> Result<Self::Mut<'_>, EntityComponentError>
ComponentIds, as determined by self. Read moreSource§unsafe 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>
ComponentIds, as determined by self.
Assumes all ComponentIds refer to mutable components. Read moreSource§impl<T: Component> From<ComponentIdFor<'_, T>> for ComponentId
impl<T: Component> From<ComponentIdFor<'_, T>> for ComponentId
Source§fn from(to_component_id: ComponentIdFor<'_, T>) -> ComponentId
fn from(to_component_id: ComponentIdFor<'_, T>) -> ComponentId
Source§impl Hash for ComponentId
impl Hash for ComponentId
Source§impl Ord for ComponentId
impl Ord for ComponentId
Source§fn cmp(&self, other: &ComponentId) -> Ordering
fn cmp(&self, other: &ComponentId) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ComponentId
impl PartialEq for ComponentId
Source§impl PartialOrd for ComponentId
impl PartialOrd for ComponentId
Source§impl SparseSetIndex for ComponentId
impl SparseSetIndex for ComponentId
Source§fn sparse_set_index(&self) -> usize
fn sparse_set_index(&self) -> usize
Source§fn get_sparse_set_index(value: usize) -> Self
fn get_sparse_set_index(value: usize) -> Self
impl Copy for ComponentId
impl Eq for ComponentId
impl StructuralPartialEq for ComponentId
Auto Trait Implementations§
impl Freeze for ComponentId
impl RefUnwindSafe for ComponentId
impl Send for ComponentId
impl Sync for ComponentId
impl Unpin for ComponentId
impl UnwindSafe for ComponentId
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.