pub struct Entity { /* private fields */ }
Expand description
Lightweight unique ID, or handle, of an entity
Obtained from World::spawn
. Can be stored to refer to an entity in the future.
Enable the serde
feature on the crate to make this Serialize
able. Some applications may be
able to save space by only serializing the output of Entity::id
.
Implementations§
source§impl Entity
impl Entity
sourcepub const DANGLING: Entity = Entity{
generation:
match NonZeroU32::new(u32::MAX) {
Some(x) => x,
None =>
::core::panicking::panic("internal error: entered unreachable code"),
},
id: u32::MAX,}
pub const DANGLING: Entity = Entity{ generation: match NonZeroU32::new(u32::MAX) { Some(x) => x, None => ::core::panicking::panic("internal error: entered unreachable code"), }, id: u32::MAX,}
An Entity
that does not necessarily correspond to data in any World
Useful as a dummy value. It is possible (albeit unlikely) for a World
to contain this
entity.
sourcepub fn to_bits(self) -> NonZeroU64
pub fn to_bits(self) -> NonZeroU64
Convert to a form convenient for passing outside of rust
No particular structure is guaranteed for the returned bits.
Useful for storing entity IDs externally, or in conjunction with Entity::from_bits
and
World::spawn_at
for easy serialization. Alternatively, consider id
for more compact
representation.
sourcepub fn from_bits(bits: u64) -> Option<Entity>
pub fn from_bits(bits: u64) -> Option<Entity>
Reconstruct an Entity
previously destructured with to_bits
if the bitpattern is valid,
else None
Useful for storing entity IDs externally, or in conjunction with Entity::to_bits
and
World::spawn_at
for easy serialization.
sourcepub fn id(self) -> u32
pub fn id(self) -> u32
Extract a transiently unique identifier
No two simultaneously-live entities share the same ID, but dead entities’ IDs may collide with both live and dead entities. Useful for compactly representing entities within a specific snapshot of the world, such as when serializing.
See also World::find_entity_from_id
.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Entity
impl<'de> Deserialize<'de> for Entity
source§fn deserialize<D>(
deserializer: D
) -> Result<Entity, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>( deserializer: D ) -> Result<Entity, <D as Deserializer<'de>>::Error>where D: Deserializer<'de>,
source§impl Ord for Entity
impl Ord for Entity
source§impl PartialEq<Entity> for Entity
impl PartialEq<Entity> for Entity
source§impl PartialOrd<Entity> for Entity
impl PartialOrd<Entity> for Entity
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 Serialize for Entity
impl Serialize for Entity
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>( &self, serializer: S ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where S: Serializer,
impl Copy for Entity
impl Eq for Entity
impl StructuralEq for Entity
impl StructuralPartialEq for Entity
Auto Trait Implementations§
impl RefUnwindSafe for Entity
impl Send for Entity
impl Sync for Entity
impl Unpin for Entity
impl UnwindSafe for Entity
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§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.§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.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Serialize for Twhere
T: Serialize + ?Sized,
impl<T> Serialize for Twhere T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.