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
ComponentId
s 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>
ComponentId
s, 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>
ComponentId
s, as determined by self
. 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 FromReflect for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl FromReflect for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
fn from_reflect(reflect: &dyn PartialReflect) -> Option<Self>
Self
from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn PartialReflect>,
) -> Result<Self, Box<dyn PartialReflect>>
fn take_from_reflect( reflect: Box<dyn PartialReflect>, ) -> Result<Self, Box<dyn PartialReflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read moreSource§impl GetTypeRegistration for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl GetTypeRegistration for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn get_type_registration() -> TypeRegistration
fn get_type_registration() -> TypeRegistration
TypeRegistration
for this type.Source§fn register_type_dependencies(registry: &mut TypeRegistry)
fn register_type_dependencies(registry: &mut TypeRegistry)
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 PartialReflect for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl PartialReflect for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn clone_value(&self) -> Box<dyn PartialReflect>
fn clone_value(&self) -> Box<dyn PartialReflect>
Reflect
trait object. Read moreSource§fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
fn try_apply(&mut self, value: &dyn PartialReflect) -> Result<(), ApplyError>
Source§fn reflect_kind(&self) -> ReflectKind
fn reflect_kind(&self) -> ReflectKind
Source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
Source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
Source§fn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
Source§fn try_into_reflect(
self: Box<Self>,
) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
fn try_into_reflect( self: Box<Self>, ) -> Result<Box<dyn Reflect>, Box<dyn PartialReflect>>
Source§fn try_as_reflect(&self) -> Option<&dyn Reflect>
fn try_as_reflect(&self) -> Option<&dyn Reflect>
Source§fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
fn try_as_reflect_mut(&mut self) -> Option<&mut dyn Reflect>
Source§fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
fn into_partial_reflect(self: Box<Self>) -> Box<dyn PartialReflect>
Source§fn as_partial_reflect(&self) -> &dyn PartialReflect
fn as_partial_reflect(&self) -> &dyn PartialReflect
Source§fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
fn as_partial_reflect_mut(&mut self) -> &mut dyn PartialReflect
Source§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn PartialReflect) -> Option<bool>
Source§fn apply(&mut self, value: &(dyn PartialReflect + 'static))
fn apply(&mut self, value: &(dyn PartialReflect + 'static))
Source§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
Source§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
Source§impl Reflect for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl Reflect for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any
. Read moreSource§fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
Source§fn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
Source§fn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
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
Source§impl TriggerTargets for ComponentId
impl TriggerTargets for ComponentId
Source§fn components(&self) -> &[ComponentId]
fn components(&self) -> &[ComponentId]
Source§impl TupleStruct for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl TupleStruct for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
Source§fn field(&self, index: usize) -> Option<&dyn PartialReflect>
fn field(&self, index: usize) -> Option<&dyn PartialReflect>
index
as a
&dyn Reflect
.Source§fn field_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>
fn field_mut(&mut self, index: usize) -> Option<&mut dyn PartialReflect>
index
as a &mut dyn Reflect
.Source§fn iter_fields(&self) -> TupleStructFieldIter<'_>
fn iter_fields(&self) -> TupleStructFieldIter<'_>
Source§fn clone_dynamic(&self) -> DynamicTupleStruct
fn clone_dynamic(&self) -> DynamicTupleStruct
DynamicTupleStruct
.Source§fn get_represented_tuple_struct_info(&self) -> Option<&'static TupleStructInfo>
fn get_represented_tuple_struct_info(&self) -> Option<&'static TupleStructInfo>
None
if TypeInfo
is not available.Source§impl TypePath for ComponentId
impl TypePath for ComponentId
Source§fn type_path() -> &'static str
fn type_path() -> &'static str
Source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
Source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
Source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
Source§impl Typed for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
impl Typed for ComponentIdwhere
ComponentId: Any + Send + Sync,
usize: FromReflect + TypePath + MaybeTyped + RegisterForReflection,
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
Source§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
.Source§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
Source§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
.Source§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
.Source§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
Source§impl<T> DynamicTyped for Twhere
T: Typed,
impl<T> DynamicTyped for Twhere
T: Typed,
Source§fn reflect_type_info(&self) -> &'static TypeInfo
fn reflect_type_info(&self) -> &'static TypeInfo
Typed::type_info
.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<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.Source§impl<T> GetPath for T
impl<T> GetPath for T
Source§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn PartialReflect + 'static), ReflectPathError<'p>>
path
. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn PartialReflect + 'static), ReflectPathError<'p>>
path
. Read moreSource§fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
fn path<'p, T>(
&self,
path: impl ReflectPath<'p>,
) -> Result<&T, ReflectPathError<'p>>where
T: Reflect,
path
. Read moreSource§fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
fn path_mut<'p, T>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more