pub struct ComponentId(/* private fields */);
Expand description
A value which uniquely identifies the type of a Component
of Resource
within a
World
.
Each time a new Component
type is registered within a World
using
e.g. World::init_component
or World::init_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<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 ComponentId
impl FromReflect for ComponentId
Source§fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
Self
from a reflected value.Source§fn take_from_reflect(
reflect: Box<dyn Reflect>,
) -> Result<Self, Box<dyn Reflect>>
fn take_from_reflect( reflect: Box<dyn Reflect>, ) -> Result<Self, Box<dyn Reflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read moreSource§impl GetTypeRegistration for ComponentId
impl GetTypeRegistration for ComponentId
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 Reflect for ComponentId
impl Reflect for ComponentId
Source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any
.Source§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§fn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read moreSource§fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
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 reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
Source§fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
Source§fn apply(&mut self, value: &(dyn Reflect + 'static))
fn apply(&mut self, value: &(dyn Reflect + '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 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) -> impl ExactSizeIterator<Item = ComponentId>
fn components(&self) -> impl ExactSizeIterator<Item = ComponentId>
Source§fn entities(&self) -> impl ExactSizeIterator<Item = Entity>
fn entities(&self) -> impl ExactSizeIterator<Item = Entity>
Source§impl TupleStruct for ComponentId
impl TupleStruct for ComponentId
Source§fn field(&self, index: usize) -> Option<&dyn Reflect>
fn field(&self, index: usize) -> Option<&dyn Reflect>
index
as a
&dyn Reflect
.Source§fn field_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
fn field_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
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§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 ComponentId
impl Typed for ComponentId
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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<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 Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p>, ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read moreSource§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>,
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p>, ) -> Result<&mut (dyn Reflect + '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