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,

§

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,

§

type Item = (IndexT, DataT)

The type of the elements being iterated over.
§

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> RefUnwindSafe for SparseEntities<IndexT, DataT>where DataT: RefUnwindSafe, IndexT: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.