Struct wasmer_types::entity::PrimaryMap
source · [−]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
sourceimpl<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 keys(&self) -> Keys<K>ⓘNotable traits for Keys<K>impl<K: EntityRef> Iterator for Keys<K> type Item = K;
pub fn keys(&self) -> Keys<K>ⓘNotable traits for Keys<K>impl<K: EntityRef> Iterator for Keys<K> type Item = K;
Iterate over all the keys in this map.
sourcepub fn values(&self) -> Iter<'_, V>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = &'a T;
pub fn values(&self) -> Iter<'_, V>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = &'a T;
Iterate over all the values in this map.
sourcepub fn values_mut(&mut self) -> IterMut<'_, V>ⓘNotable traits for IterMut<'a, T>impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
pub fn values_mut(&mut self) -> IterMut<'_, V>ⓘNotable traits for IterMut<'a, T>impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
Iterate over all the values in this map, mutable edition.
sourcepub fn iter(&self) -> Iter<'_, K, V>ⓘNotable traits for Iter<'a, K, V>impl<'a, K: EntityRef, V> Iterator for Iter<'a, K, V> type Item = (K, &'a V);
pub fn iter(&self) -> Iter<'_, K, V>ⓘNotable traits for Iter<'a, K, V>impl<'a, K: EntityRef, V> Iterator for Iter<'a, K, V> type Item = (K, &'a V);
Iterate over all the keys and values in this map.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>ⓘNotable traits for IterMut<'a, K, V>impl<'a, K: EntityRef, V> Iterator for IterMut<'a, K, V> type Item = (K, &'a mut V);
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>ⓘNotable traits for IterMut<'a, K, V>impl<'a, K: EntityRef, V> Iterator for IterMut<'a, K, V> type Item = (K, &'a mut 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
sourceimpl<K, V> Archive for PrimaryMap<K, V> where
K: EntityRef,
Vec<V>: Archive,
PhantomData<K>: Archive,
impl<K, V> Archive for PrimaryMap<K, V> where
K: EntityRef,
Vec<V>: Archive,
PhantomData<K>: Archive,
sourceimpl<K: Clone, V: Clone> Clone for PrimaryMap<K, V> where
K: EntityRef,
impl<K: Clone, V: Clone> Clone for PrimaryMap<K, V> where
K: EntityRef,
sourcefn clone(&self) -> PrimaryMap<K, V>
fn clone(&self) -> PrimaryMap<K, V>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<K, V> Default for PrimaryMap<K, V> where
K: EntityRef,
impl<K, V> Default for PrimaryMap<K, V> where
K: EntityRef,
sourceimpl<'de, K, V> Deserialize<'de> for PrimaryMap<K, V> where
K: EntityRef,
V: Deserialize<'de>,
impl<'de, K, V> Deserialize<'de> for PrimaryMap<K, V> where
K: EntityRef,
V: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<__D: Fallible + ?Sized, K, V> Deserialize<PrimaryMap<K, V>, __D> for Archived<PrimaryMap<K, V>> where
K: EntityRef,
Vec<V>: Archive,
Archived<Vec<V>>: Deserialize<Vec<V>, __D>,
PhantomData<K>: Archive,
Archived<PhantomData<K>>: 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,
Archived<Vec<V>>: Deserialize<Vec<V>, __D>,
PhantomData<K>: Archive,
Archived<PhantomData<K>>: Deserialize<PhantomData<K>, __D>,
sourcefn deserialize(
&self,
deserializer: &mut __D
) -> Result<PrimaryMap<K, V>, __D::Error>
fn deserialize(
&self,
deserializer: &mut __D
) -> Result<PrimaryMap<K, V>, __D::Error>
Deserializes using the given deserializer
sourceimpl<K, V> FromIterator<V> for PrimaryMap<K, V> where
K: EntityRef,
impl<K, V> FromIterator<V> for PrimaryMap<K, V> where
K: EntityRef,
sourcefn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = V>,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = V>,
Creates a value from an iterator. Read more
sourceimpl<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.
sourceimpl<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
.
sourceimpl<K, V> IntoIterator for PrimaryMap<K, V> where
K: EntityRef,
impl<K, V> IntoIterator for PrimaryMap<K, V> where
K: EntityRef,
sourceimpl<'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,
sourceimpl<'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,
sourceimpl<K, V> MemoryUsage for PrimaryMap<K, V> where
K: EntityRef,
V: MemoryUsage,
impl<K, V> MemoryUsage for PrimaryMap<K, V> where
K: EntityRef,
V: MemoryUsage,
sourcefn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize
fn size_of_val(&self, tracker: &mut dyn MemoryUsageTracker) -> usize
Returns the size of the referenced value in bytes. Read more
sourceimpl<K: PartialEq, V: PartialEq> PartialEq<PrimaryMap<K, V>> for PrimaryMap<K, V> where
K: EntityRef,
impl<K: PartialEq, V: PartialEq> PartialEq<PrimaryMap<K, V>> for PrimaryMap<K, V> where
K: EntityRef,
sourcefn eq(&self, other: &PrimaryMap<K, V>) -> bool
fn eq(&self, other: &PrimaryMap<K, V>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &PrimaryMap<K, V>) -> bool
fn ne(&self, other: &PrimaryMap<K, V>) -> bool
This method tests for !=
.
sourceimpl<K, V> Serialize for PrimaryMap<K, V> where
K: EntityRef,
V: Serialize,
impl<K, V> Serialize for PrimaryMap<K, V> where
K: EntityRef,
V: Serialize,
sourceimpl<__S: Fallible + ?Sized, K, V> Serialize<__S> for PrimaryMap<K, V> where
K: EntityRef,
Vec<V>: Serialize<__S>,
PhantomData<K>: Serialize<__S>,
impl<__S: Fallible + ?Sized, K, V> Serialize<__S> for PrimaryMap<K, V> where
K: EntityRef,
Vec<V>: Serialize<__S>,
PhantomData<K>: Serialize<__S>,
impl<K: Eq, V: Eq> Eq for PrimaryMap<K, V> where
K: EntityRef,
impl<K, V> StructuralEq for PrimaryMap<K, V> where
K: EntityRef,
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
sourceimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
sourcefn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> ArchiveUnsized for T where
T: Archive,
impl<T> ArchiveUnsized for T where
T: Archive,
type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
The archived counterpart of this type. Unlike Archive
, it may be unsized. Read more
type MetadataResolver = ()
type MetadataResolver = ()
The resolver for the metadata of this type. Read more
sourceunsafe fn resolve_metadata(
&self,
usize,
<T as ArchiveUnsized>::MetadataResolver,
*mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
)
unsafe fn resolve_metadata(
&self,
usize,
<T as ArchiveUnsized>::MetadataResolver,
*mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
)
Creates the archived version of the metadata for this value at the given position and writes it to the given output. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.