Skip to main content

Entity

Struct Entity 

Source
pub struct Entity {
    index: u32,
    generation: u32,
    name: &'static str,
}
Expand description

A handle to an entity.

The handle is a plain value: it stays valid across world mutations as long as the entity lives, and resolves to nothing once the entity is despawned.

It also carries a name, which Debug prints. A name is given where the entity is made: a crate::bundle! names it after its own source position, crate::DynamicBundle::named and crate::ScopeMut::spawn_named after the string the caller passed, and crate::World::reserve_entity at the reservation. Two handles to one entity can carry different names and still be equal, because a handle restored from Entity::to_bits has no name to restore; crate::Scope::entity_name reads the one the row stores.

Fields§

§index: u32§generation: u32§name: &'static str

Implementations§

Source§

impl Entity

Source

pub const fn from_raw(index: u32, generation: u32) -> Self

Build a handle from raw parts.

The handle only refers to an entity if it was produced by the same world, so this is for restoring a handle that came from that world (a save file, for example).

Source

pub const fn name(self) -> &'static str

The name part, empty when the handle was restored rather than spawned.

Source

pub const fn index(self) -> u32

The index part.

Source

pub const fn generation(self) -> u32

The generation part.

Source

pub const fn to_bits(self) -> u64

The two parts as one value, generation high.

This is not the order Ord uses: the comparison is by index first, then generation, which is what makes entities spawned together sort together.

Source

pub const fn from_bits(bits: u64) -> Self

The handle Entity::to_bits produced.

The handle only refers to an entity if it was produced by the same world, so this is for restoring a handle that came from that world. The restored handle carries no name.

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Entity

Source§

impl Debug for Entity

Prints the name and the bits the handle travels as, and not the index and generation they are made of: those are the allocator’s business, while the bits are the only part a caller holds when the handle came over a wire.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Entity

Source§

impl From<&Entity> for EntityProxy

Available on crate feature reflect only.
Source§

fn from(value: &Entity) -> Self

Converts to this type from the input type.
Source§

impl From<EntityProxy> for Entity

Available on crate feature reflect only.
Source§

fn from(proxy: EntityProxy) -> Self

Converts to this type from the input type.
Source§

impl Hash for Entity

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Entity

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Entity

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Entity

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Query for Entity

Asks for the entity itself.

It is an item like any other, so it can be written first, last, or on its own: a query over Entity alone yields every entity the scope sees.

Source§

type Item<'a> = Entity

What one matched row yields. Read more
Source§

type Plan<'w> = &'w [Entity]

What is resolved once per archetype and then read once per row. Read more
Source§

fn prepare<'w>(builder: &mut PlanBuilder<'w>) -> Option<Self::Plan<'w>>

Resolve the plan for one archetype. Read more
Source§

fn read<'a, 'w: 'a>(plan: &'a mut Self::Plan<'w>, row: usize) -> Self::Item<'a>

Read the row at row through the resolved plan. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> Component for T
where T: 'static,

Source§

impl<T> DynClone for T
where T: Clone,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more