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

A primary mapping K -> V allocating dense entity references.

The PrimaryMap data structure uses the dense index space to implement a map with a vector.

A primary map contains the main definition of an entity, and it can be used to allocate new entity references with the push method.

There should only be a single PrimaryMap instance for a given EntityRef type, otherwise conflicting references will be created. Using unknown keys for indexing will cause a panic.

Note that PrimaryMap doesn’t implement Deref or DerefMut, which would allow &PrimaryMap<K, V> to convert to &[V]. One of the main advantages of PrimaryMap is that it only allows indexing with the distinct EntityRef key type, so converting to a plain slice would make it easier to use incorrectly. To make a slice of a PrimaryMap, use into_boxed_slice.

Implementations§

source§

impl<K, V> PrimaryMap<K, V>where K: EntityRef,

source

pub fn new() -> PrimaryMap<K, V>

Create a new empty map.

source

pub fn with_capacity(capacity: usize) -> PrimaryMap<K, V>

Create a new empty map with the given capacity.

source

pub fn is_valid(&self, k: K) -> bool

Check if k is a valid key in the map.

source

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

Get the element at k if it exists.

source

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

Get the element at k if it exists, mutable version.

source

pub fn is_empty(&self) -> bool

Is this map completely empty?

source

pub fn len(&self) -> usize

Get the total number of entity references created.

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 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 clear(&mut self)

Remove all entries from this map.

source

pub fn next_key(&self) -> K

Get the key that will be assigned to the next pushed value.

source

pub fn push(&mut self, v: V) -> K

Append v to the mapping, assigning a new key which is returned.

source

pub fn last(&self) -> Option<(K, &V)>

Returns the last element that was inserted in the map.

source

pub fn last_mut(&mut self) -> Option<(K, &mut V)>

Returns the last element that was inserted in the map.

source

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

Reserves capacity for at least additional more elements to be inserted.

source

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

Reserves the minimum capacity for exactly additional more elements to be inserted.

source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the PrimaryMap as much as possible.

source

pub fn into_boxed_slice(self) -> BoxedSlice<K, V>

Consumes this PrimaryMap and produces a BoxedSlice.

source

pub fn binary_search_values_by_key<'a, B, F>( &'a self, b: &B, f: F ) -> Result<K, K>where F: FnMut(&'a V) -> B, B: Ord,

Performs a binary search on the values with a key extraction function.

Assumes that the values are sorted by the key extracted by the function.

If the value is found then Ok(K) is returned, containing the entity key of the matching value.

If there are multiple matches, then any one of the matches could be returned.

If the value is not found then Err(K) is returned, containing the entity key where a matching element could be inserted while maintaining sorted order.

Trait Implementations§

source§

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

source§

fn clone(&self) -> PrimaryMap<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 PrimaryMap<K, V>where K: Debug + EntityRef, V: Debug,

source§

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

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

impl<K, V> Default for PrimaryMap<K, V>where K: EntityRef,

source§

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

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

impl<'de, K, V> Deserialize<'de> for PrimaryMap<K, V>where K: EntityRef, V: Deserialize<'de>,

source§

fn deserialize<__D>( __deserializer: __D ) -> Result<PrimaryMap<K, V>, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<K, V> FromIterator<V> for PrimaryMap<K, V>where K: EntityRef,

source§

fn from_iter<T>(iter: T) -> PrimaryMap<K, V>where T: IntoIterator<Item = V>,

Creates a value from an iterator. Read more
source§

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

source§

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

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 PrimaryMap<K, V>where K: EntityRef,

Immutable indexing into an PrimaryMap. The indexed value must be in the map.

§

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 PrimaryMap<K, V>where K: EntityRef,

Mutable indexing into an PrimaryMap.

source§

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

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

impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>where K: EntityRef,

§

type Item = (K, &'a V)

The type of the elements being iterated over.
§

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

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

fn into_iter(self) -> <&'a PrimaryMap<K, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, K, V> IntoIterator for &'a mut PrimaryMap<K, V>where K: EntityRef,

§

type Item = (K, &'a mut V)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, K, V>

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

fn into_iter(self) -> <&'a mut PrimaryMap<K, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V> IntoIterator for PrimaryMap<K, V>where K: EntityRef,

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

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

fn into_iter(self) -> <PrimaryMap<K, V> as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

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

source§

fn eq(&self, other: &PrimaryMap<K, V>) -> 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> Serialize for PrimaryMap<K, V>where K: EntityRef, V: Serialize,

source§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<K, V> Eq for PrimaryMap<K, V>where K: Eq + EntityRef, V: Eq,

source§

impl<K, V> StructuralEq for PrimaryMap<K, V>where K: EntityRef,

source§

impl<K, V> StructuralPartialEq for PrimaryMap<K, V>where K: EntityRef,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<K, V> UnwindSafe for PrimaryMap<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> CallHasher for Twhere T: Hash + ?Sized,

source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

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

source§

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 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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,