pub struct SecondaryMap<K, V>where
    K: EntityRef,
    V: Clone,{ /* private fields */ }
Expand description

A mapping K -> V for densely indexed entity references.

The SecondaryMap data structure uses the dense index space to implement a map with a vector. Unlike PrimaryMap, an SecondaryMap can’t be used to allocate entity references. It is used to associate secondary information with entities.

The map does not track if an entry for a key has been inserted or not. Instead it behaves as if all keys have a default entry from the beginning.

Implementations§

source§

impl<K, V> SecondaryMap<K, V>where K: EntityRef, V: Clone,

Shared SecondaryMap implementation for all value types.

source

pub fn new() -> Selfwhere V: Default,

Create a new empty map.

source

pub fn with_capacity(capacity: usize) -> Selfwhere V: Default,

Create a new, empty map with the specified capacity.

The map will be able to hold exactly capacity elements without reallocating.

source

pub fn with_default(default: V) -> Self

Create a new empty map with a specified default value.

This constructor does not require V to implement Default.

source

pub fn capacity(&self) -> usize

Returns the number of elements the map can hold without reallocating.

source

pub fn get(&self, k: K) -> Option<&V>

Get the element at k if it exists.

source

pub fn is_empty(&self) -> bool

Is this map completely empty?

source

pub fn clear(&mut self)

Remove all entries from this map.

source

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

Iterate over all the keys and values in this map.

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Iterate over all the keys and values in this map, mutable edition.

source

pub fn keys(&self) -> Keys<K>

Iterate over all the keys in this map.

source

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

Iterate over all the values in this map.

source

pub fn values_mut(&mut self) -> IterMut<'_, V>

Iterate over all the values in this map, mutable edition.

source

pub fn resize(&mut self, n: usize)

Resize the map to have n entries by adding default entries as needed.

Trait Implementations§

source§

impl<K, V> Clone for SecondaryMap<K, V>where K: EntityRef + Clone, V: Clone + Clone,

source§

fn clone(&self) -> SecondaryMap<K, V>

Returns a copy 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<K, V> Debug for SecondaryMap<K, V>where K: EntityRef + Debug, V: Clone + Debug,

source§

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

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

impl<K, V> Default for SecondaryMap<K, V>where K: EntityRef, V: Clone + Default,

source§

fn default() -> SecondaryMap<K, V>

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

impl<K, V> Hash for SecondaryMap<K, V>where K: EntityRef + Hash, V: Clone + Hash,

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<K, V> Index<K> for SecondaryMap<K, V>where K: EntityRef, V: Clone,

Immutable indexing into an SecondaryMap.

All keys are permitted. Untouched entries have the default value.

§

type Output = V

The returned type after indexing.
source§

fn index(&self, k: K) -> &V

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

impl<K, V> IndexMut<K> for SecondaryMap<K, V>where K: EntityRef, V: Clone,

Mutable indexing into an SecondaryMap.

The map grows as needed to accommodate new keys.

source§

fn index_mut(&mut self, k: K) -> &mut V

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

impl<K, V> PartialEq<SecondaryMap<K, V>> for SecondaryMap<K, V>where K: EntityRef, V: Clone + PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K, V> Eq for SecondaryMap<K, V>where K: EntityRef, V: Clone + PartialEq + Eq,

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for SecondaryMap<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for SecondaryMap<K, V>where K: Send, V: Send,

§

impl<K, V> Sync for SecondaryMap<K, V>where K: Sync, V: Sync,

§

impl<K, V> Unpin for SecondaryMap<K, V>where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for SecondaryMap<K, V>where K: UnwindSafe, V: 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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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

§

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 Twhere U: TryFrom<T>,

§

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.