Struct bevy_ecs::component::ComponentId
source · pub struct ComponentId(/* private fields */);Expand description
A value which uniquely identifies the type of a Component within a
World.
Each time a new Component type is registered within a World using
World::init_component or
World::init_component_with_descriptor,
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<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§fn eq(&self, other: &ComponentId) -> bool
fn eq(&self, other: &ComponentId) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for ComponentId
impl PartialOrd for ComponentId
source§fn partial_cmp(&self, other: &ComponentId) -> Option<Ordering>
fn partial_cmp(&self, other: &ComponentId) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§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 StructuralEq for ComponentId
impl StructuralPartialEq for ComponentId
Auto Trait Implementations§
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
§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
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.