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,
impl<K, V> PrimaryMap<K, V>where
K: EntityRef,
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new empty map with the given capacity.
sourcepub fn get_mut(&mut self, k: K) -> Option<&mut V>
pub fn get_mut(&mut self, k: K) -> Option<&mut V>
Get the element at k
if it exists, mutable version.
sourcepub fn values_mut(&mut self) -> IterMut<'_, V> ⓘ
pub fn values_mut(&mut self) -> IterMut<'_, V> ⓘ
Iterate over all the values in this map, mutable edition.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
Iterate over all the keys and values in this map, mutable edition.
sourcepub fn push(&mut self, v: V) -> K
pub fn push(&mut self, v: V) -> K
Append v
to the mapping, assigning a new key which is returned.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional
more elements to be inserted.
sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves the minimum capacity for exactly additional
more elements to be inserted.
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the PrimaryMap
as much as possible.
sourcepub fn into_boxed_slice(self) -> BoxedSlice<K, V>
pub fn into_boxed_slice(self) -> BoxedSlice<K, V>
Consumes this PrimaryMap
and produces a BoxedSlice
.
Trait Implementations§
source§impl<K, V> Archive for PrimaryMap<K, V>
impl<K, V> Archive for PrimaryMap<K, V>
source§type Archived = ArchivedPrimaryMap<K, V>
type Archived = ArchivedPrimaryMap<K, V>
source§type Resolver = PrimaryMapResolver<K, V>
type Resolver = PrimaryMapResolver<K, V>
source§fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
source§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize
. Read moresource§impl<K, V: Clone> Clone for PrimaryMap<K, V>
impl<K, V: Clone> Clone for PrimaryMap<K, V>
source§fn clone(&self) -> PrimaryMap<K, V>
fn clone(&self) -> PrimaryMap<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<K, V: Debug> Debug for PrimaryMap<K, V>
impl<K, V: Debug> Debug for PrimaryMap<K, V>
source§impl<K, V> Default for PrimaryMap<K, V>where
K: EntityRef,
impl<K, V> Default for PrimaryMap<K, V>where
K: EntityRef,
source§impl<__D: Fallible + ?Sized, K, V> Deserialize<PrimaryMap<K, V>, __D> for Archived<PrimaryMap<K, V>>where
K: EntityRef,
Vec<V>: Archive,
<Vec<V> as Archive>::Archived: Deserialize<Vec<V>, __D>,
PhantomData<K>: Archive,
<PhantomData<K> as Archive>::Archived: Deserialize<PhantomData<K>, __D>,
impl<__D: Fallible + ?Sized, K, V> Deserialize<PrimaryMap<K, V>, __D> for Archived<PrimaryMap<K, V>>where
K: EntityRef,
Vec<V>: Archive,
<Vec<V> as Archive>::Archived: Deserialize<Vec<V>, __D>,
PhantomData<K>: Archive,
<PhantomData<K> as Archive>::Archived: Deserialize<PhantomData<K>, __D>,
source§fn deserialize(
&self,
deserializer: &mut __D,
) -> Result<PrimaryMap<K, V>, <__D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut __D, ) -> Result<PrimaryMap<K, V>, <__D as Fallible>::Error>
source§impl<K, V> FromIterator<V> for PrimaryMap<K, V>where
K: EntityRef,
impl<K, V> FromIterator<V> for PrimaryMap<K, V>where
K: EntityRef,
source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = V>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = V>,
source§impl<K, V: Hash> Hash for PrimaryMap<K, V>
impl<K, V: Hash> Hash for PrimaryMap<K, V>
source§impl<K, V> Index<K> for PrimaryMap<K, V>where
K: EntityRef,
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.
source§impl<K, V> IndexMut<K> for PrimaryMap<K, V>where
K: EntityRef,
impl<K, V> IndexMut<K> for PrimaryMap<K, V>where
K: EntityRef,
Mutable indexing into an PrimaryMap
.
source§impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>where
K: EntityRef,
impl<'a, K, V> IntoIterator for &'a PrimaryMap<K, V>where
K: EntityRef,
source§impl<'a, K, V> IntoIterator for &'a mut PrimaryMap<K, V>where
K: EntityRef,
impl<'a, K, V> IntoIterator for &'a mut PrimaryMap<K, V>where
K: EntityRef,
source§impl<K, V> IntoIterator for PrimaryMap<K, V>where
K: EntityRef,
impl<K, V> IntoIterator for PrimaryMap<K, V>where
K: EntityRef,
source§impl<K, V: PartialEq> PartialEq for PrimaryMap<K, V>
impl<K, V: PartialEq> PartialEq for PrimaryMap<K, V>
impl<K, V: Eq> Eq for PrimaryMap<K, V>
impl<K, V> StructuralPartialEq for PrimaryMap<K, V>where
K: EntityRef,
Auto Trait Implementations§
impl<K, V> Freeze for PrimaryMap<K, V>
impl<K, V> RefUnwindSafe for PrimaryMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for PrimaryMap<K, V>
impl<K, V> Sync for PrimaryMap<K, V>
impl<K, V> Unpin for PrimaryMap<K, V>
impl<K, V> UnwindSafe for PrimaryMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive
, it may be
unsized. Read moresource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.