wasmer_types::entity

Struct 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§

Source§

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

Source

pub fn new() -> Self

Create a new empty map.

Source

pub fn with_capacity(capacity: usize) -> Self

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<&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.

Trait Implementations§

Source§

impl<K, V> Archive for PrimaryMap<K, V>

Source§

type Archived = ArchivedPrimaryMap<K, V>

The archived representation of this type. Read more
Source§

type Resolver = PrimaryMapResolver<K, V>

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)

Creates the archived version of this value at the given position and writes it to the given output. Read more
Source§

const COPY_OPTIMIZATION: CopyOptimization<Self> = _

An optimization flag that allows the bytes of this type to be copied directly to a writer instead of calling serialize. Read more
Source§

impl<K, V: Clone> Clone for PrimaryMap<K, V>
where K: EntityRef + 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> Debug for PrimaryMap<K, V>
where K: EntityRef + Debug,

Source§

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

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

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

Source§

fn default() -> Self

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

impl<__D: Fallible + ?Sized, K, V> Deserialize<PrimaryMap<K, V>, __D> for Archived<PrimaryMap<K, V>>

Source§

fn deserialize( &self, deserializer: &mut __D, ) -> Result<PrimaryMap<K, V>, <__D as Fallible>::Error>

Deserializes using the given deserializer
Source§

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

Source§

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

Creates a value from an iterator. Read more
Source§

impl<K, V: Hash> Hash for PrimaryMap<K, V>
where K: EntityRef + 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 PrimaryMap<K, V>
where K: EntityRef,

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

Source§

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,

Source§

type Item = (K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, K, 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<'a, K, V> IntoIterator for &'a mut PrimaryMap<K, V>
where K: EntityRef,

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, K, 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<K, V> IntoIterator for PrimaryMap<K, V>
where K: EntityRef,

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, 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<K, V: PartialEq> PartialEq for PrimaryMap<K, V>
where K: EntityRef + PartialEq,

Source§

fn eq(&self, other: &PrimaryMap<K, 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<__S: Fallible + ?Sized, K, V> Serialize<__S> for PrimaryMap<K, V>
where K: EntityRef, Vec<V>: Serialize<__S>, PhantomData<K>: Serialize<__S>,

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<Self as Archive>::Resolver, <__S as Fallible>::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
Source§

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

Source§

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>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

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

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

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> ArchiveUnsized for T
where T: Archive,

Source§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
Source§

fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata

Creates the archived version of the metadata for this value.
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, dst: *mut u8)

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

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

Source§

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

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

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

Source§

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

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

impl<Q, K> Equivalent<K> for Q
where 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 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.

Source§

impl<T> LayoutRaw for T

Source§

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

Returns the layout of the type.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Fallible + Writer + ?Sized,

Source§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived 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.