Skip to main content

Entities

Struct Entities 

Source
pub(crate) struct Entities {
    meta: Vec<Meta>,
    free: Vec<u32>,
    reserved: usize,
}
Expand description

Allocates entity handles and maps them to their row in an archetype.

Fields§

§meta: Vec<Meta>§free: Vec<u32>

Indices whose entity is despawned and whose current generation is already recorded in meta.

§reserved: usize

How many indices are reserved but not spawned. Every reserved index is flagged in its Meta, so releasing one is a flag flip rather than a search.

Implementations§

Source§

impl Entities

Source

pub(crate) fn contains(&self, entity: Entity) -> bool

Whether the handle refers to a live entity.

Source

pub(crate) fn location( &self, entity: Entity, ) -> Result<Location, EntityAccessError>

Where the entity lives.

A handle whose index was never allocated, whose generation was bumped by a despawn, or whose index is reserved but not spawned yet answers EntityAccessError::NotAlive.

Source

pub(crate) fn set_location(&mut self, entity: Entity, location: Location)

Record where an entity lives, replacing any earlier location.

Panics when the handle is not live: a location is only ever recorded for an entity that was just allocated or reserved.

Source

fn index(&mut self) -> usize

Reuse a freed index, or grow meta for a fresh one.

Source

pub(crate) fn reserve(&mut self, name: &'static str) -> Entity

Hand out a fresh handle and mark the index as reserved.

Source

pub(crate) fn alloc(&mut self, name: &'static str) -> Entity

Hand out a handle for a new entity, reusing a free index when possible.

Source

pub(crate) fn is_reserved(&self, entity: Entity) -> bool

Whether the handle came from reserve and has not been spawned or freed yet.

Source

pub(crate) fn take_reserved(&mut self, entity: Entity) -> bool

Mark a reserved handle as spawned.

Returns whether the handle was reserved; a handle that is not is left untouched.

Source

pub(crate) fn free(&mut self, entity: Entity) -> bool

Release a dead entity’s index, so a later entity reuses it with a new generation.

Returns whether the handle referred to a reserved or live entity; a stale handle, or one already freed, is a no-op.

Trait Implementations§

Source§

impl Default for Entities

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Component for T
where T: 'static,

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, 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