Struct EntityAllocator

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

Allocates and manages entity IDs and generations, allowing safe reuse of entity IDs.

§Fields

  • generations: Per-id generation counters used to validate entity liveness.
  • free_ids: Pool of reusable entity IDs.

§Safety

  • Reuse safety is enforced by bumping the generation on destroy, invalidating stale Entity values that refer to the same id with an older generation.

Implementations§

Source§

impl EntityAllocator

Source

pub fn create(&mut self) -> Entity

Creates a new entity, reusing an ID if possible, otherwise assigning a new one.

§Returns
  • Entity: The newly allocated entity identifier (with current generation for its id).
Source

pub fn destroy(&mut self, entity: Entity)

Destroys an entity, marking it as dead and adding its ID back to free pool.

§Parameters
  • entity: The entity to destroy. If already dead or invalid, this is a no-op.
Source

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

Checks if an entity is alive by comparing its generation against stored generation.

§Parameters
  • entity: The entity identifier to check.
§Returns
  • bool: true if the entity is currently alive; false otherwise.

Trait Implementations§

Source§

impl Default for EntityAllocator

Source§

fn default() -> EntityAllocator

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.