Struct SparseEntities

Source
pub struct SparseEntities<IndexT, DataT> { /* private fields */ }
Expand description

This is a sandwich of HashMap and Sequence.

§Features:

  • stable indices and not redeemable
  • generated indices

Use cases:

  • you’re removing more entities than you are adding
  • you don’t care about relaiming ids

Implementations§

Source§

impl<IndexT, DataT> SparseEntities<IndexT, DataT>
where IndexT: Successor + Clone + Copy + Hash + Eq + Default,

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn get(&self, index: IndexT) -> Option<&DataT>

Source

pub fn get_mut(&mut self, index: IndexT) -> Option<&mut DataT>

Source

pub fn remove(&mut self, index: IndexT) -> DataT

Panic if index is invalid

Source

pub fn alloc(&mut self, data: DataT) -> IndexT

Source

pub fn iter(&self) -> impl Iterator<Item = (IndexT, &DataT)>

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (IndexT, &mut DataT)>

Trait Implementations§

Source§

impl<IndexT, DataT> Default for SparseEntities<IndexT, DataT>
where IndexT: Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<IndexT, DataT> Index<IndexT> for SparseEntities<IndexT, DataT>
where IndexT: Successor + Clone + Copy + Hash + Eq + Default,

Source§

type Output = DataT

The returned type after indexing.
Source§

fn index(&self, index: IndexT) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<IndexT, DataT> IndexMut<IndexT> for SparseEntities<IndexT, DataT>
where IndexT: Successor + Clone + Copy + Hash + Eq + Default,

Source§

fn index_mut(&mut self, index: IndexT) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<IndexT, DataT> IntoIterator for SparseEntities<IndexT, DataT>
where IndexT: Successor + Clone + Copy + Default + Hash + Eq,

Source§

type Item = (IndexT, DataT)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<IndexT, DataT>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<IndexT, DataT> Freeze for SparseEntities<IndexT, DataT>
where IndexT: Freeze,

§

impl<IndexT, DataT> RefUnwindSafe for SparseEntities<IndexT, DataT>
where IndexT: RefUnwindSafe, DataT: RefUnwindSafe,

§

impl<IndexT, DataT> Send for SparseEntities<IndexT, DataT>
where IndexT: Send, DataT: Send,

§

impl<IndexT, DataT> Sync for SparseEntities<IndexT, DataT>
where IndexT: Sync, DataT: Sync,

§

impl<IndexT, DataT> Unpin for SparseEntities<IndexT, DataT>
where IndexT: Unpin, DataT: Unpin,

§

impl<IndexT, DataT> UnwindSafe for SparseEntities<IndexT, DataT>
where IndexT: UnwindSafe, DataT: UnwindSafe,

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.