EntityMap

Struct EntityMap 

Source
pub struct EntityMap<E: Entity, V> { /* private fields */ }
Expand description

A Vec-backed map keyed by EntityId<E>.

Implementations§

Source§

impl<E: Entity, V> EntityMap<E, V>

Source

pub fn new() -> Self

Creates an empty EntityMap.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty EntityMap with space for at least capacity values.

Source

pub fn into_entity_vec(self) -> EntityVec<E, Option<V>>

Cheap conversion to an EntityVec<E, Option<V>>

Source

pub fn len(&self) -> usize

Returns the number of stored key-value pairs.

Source

pub fn capacity(&self) -> usize

Returns the capacity of the backing storage.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no values.

Source

pub fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more values.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the backing vector to fit the highest occupied entity ID.

Source

pub fn contains_key(&self, entity_id: EntityId<E>) -> bool

Returns true if entity_id is present in the map.

Source

pub fn get(&self, entity_id: EntityId<E>) -> Option<&V>

Returns the value for entity_id, or None if not present.

Source

pub fn get_mut(&mut self, entity_id: EntityId<E>) -> Option<&mut V>

Returns the value for entity_id mutably, or None if not present.

Source

pub fn insert(&mut self, entity_id: EntityId<E>, value: V) -> Option<V>

Inserts value for entity_id, returning the previous value if one existed.

Source

pub fn get_or_insert(&mut self, entity_id: EntityId<E>, value: V) -> &mut V

Returns the value for entity_id, inserting value if it is not already present.

Source

pub fn get_or_insert_with<F>(&mut self, entity_id: EntityId<E>, f: F) -> &mut V
where F: FnOnce() -> V,

Returns the value for entity_id, inserting a value from f if it is not already present.

Source

pub fn remove(&mut self, entity_id: EntityId<E>) -> Option<V>

Removes and returns the value for entity_id, if present.

Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs.

Source

pub fn iter(&self) -> Iter<'_, E, V>

Returns an iterator over (EntityId<E>, &V) pairs.

Trait Implementations§

Source§

impl<E: Clone + Entity, V: Clone> Clone for EntityMap<E, V>

Source§

fn clone(&self) -> EntityMap<E, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Entity, V: Debug> Debug for EntityMap<E, V>

Source§

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

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

impl<E: Entity, V> Default for EntityMap<E, V>

Source§

fn default() -> Self

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

impl<E: Entity, V> Extend<(EntityId<E>, V)> for EntityMap<E, V>

Source§

fn extend<I: IntoIterator<Item = (EntityId<E>, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<E: Entity, V> FromIterator<(EntityId<E>, V)> for EntityMap<E, V>

Source§

fn from_iter<I: IntoIterator<Item = (EntityId<E>, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, E: Entity, V> IntoIterator for &'a EntityMap<E, V>

Source§

type Item = (EntityId<E>, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, E, V>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E: PartialEq + Entity, V: PartialEq> PartialEq for EntityMap<E, V>

Source§

fn eq(&self, other: &EntityMap<E, V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<E: Eq + Entity, V: Eq> Eq for EntityMap<E, V>

Source§

impl<E: Entity, V> StructuralPartialEq for EntityMap<E, V>

Auto Trait Implementations§

§

impl<E, V> Freeze for EntityMap<E, V>

§

impl<E, V> RefUnwindSafe for EntityMap<E, V>

§

impl<E, V> Send for EntityMap<E, V>
where E: Send, V: Send,

§

impl<E, V> Sync for EntityMap<E, V>
where E: Sync, V: Sync,

§

impl<E, V> Unpin for EntityMap<E, V>
where E: Unpin, V: Unpin,

§

impl<E, V> UnwindSafe for EntityMap<E, V>
where E: UnwindSafe, V: 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
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V