Skip to main content

Entities

Struct Entities 

Source
pub struct Entities { /* private fields */ }
Expand description

The entity allocator: slot generations, the free list, and the reservation counter.

Implementations§

Source§

impl Entities

Source

pub fn new() -> Entities

An allocator with no slots.

Source

pub fn alloc(&mut self) -> Entity

Allocate an entity, recycling a freed slot when one is available. The recycled slot keeps the generation it was bumped to at despawn, so old handles to it stay invalid.

Source

pub fn reserve(&self) -> Entity

Reserve a fresh entity id without taking &mut self. Lock-free, so it is safe to call from worker threads while recording commands. Reserved ids are always fresh (never recycled) and carry the first generation; call flush under &mut self before looking them up.

Source

pub fn flush(&mut self)

Materialize any reserved-but-unmaterialized ids into the metadata table, marking them alive. Idempotent.

Source

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

Despawn an entity. Validates the generation, so a stale or already-dead handle is a no-op returning false. Bumps the slot’s generation and frees the index for reuse.

Source

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

Whether the handle refers to a currently-live entity. Reflects only materialized state; reserved ids appear after flush.

Trait Implementations§

Source§

impl Debug for Entities

Source§

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

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

impl Default for Entities

Source§

fn default() -> Entities

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.