Skip to main content

Entities

Struct Entities 

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

Hands out entity slots and recycles them.

Implementations§

Source§

impl Entities

Source

pub fn new() -> Self

An allocator with no slots yet.

Source

pub fn len(&self) -> usize

How many entities are alive.

Source

pub fn is_empty(&self) -> bool

Whether no entity is alive.

Source

pub fn capacity(&self) -> usize

The highest slot ever allocated, which bounds an ordered walk.

Source

pub fn spawn(&mut self) -> Entity

Allocate an entity, reusing a free slot when one exists.

Reuse is newest-first, which keeps the index range compact: an ordered query walks slots rather than entities, so a store whose indices are spread thin pays for the gaps.

§Panics

Never in practice: the slot count is bounded by u32::MAX, and a tree with four billion live entities has other problems. Written as a saturating count rather than an unwrap so there is no panic to reason about.

Source

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

Whether this exact handle still names a live entity.

Both halves are checked. A handle whose slot is alive but whose generation is stale names an entity that no longer exists, and is the whole reason the generation is there.

Source

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

Free an entity’s slot. Returns whether it was alive to begin with.

Despawning an already-dead handle is a no-op rather than an error: it is the natural outcome of two systems both deciding something should go, and turning it into a failure would make every caller check first.

Source

pub fn iter(&self) -> impl Iterator<Item = Entity> + '_

Every live entity, in ascending slot order.

The order is part of the contract, not an accident of the representation: see the crate docs.

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