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> Archive for SecondaryMap<K, V>where K: EntityRef, V: Clone + Archive, Vec<V>: Archive, PhantomData<K>: Archive,

§

type Archived = ArchivedSecondaryMap<K, V>

The archived representation of this type. Read more
§

type Resolver = SecondaryMapResolver<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§

unsafe fn resolve( &self, pos: usize, resolver: Self::Resolver, out: *mut Self::Archived )

Creates the archived version of this value at the given position and writes it to the given output. Read more
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() -> Self

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

impl<__D: Fallible + ?Sized, K, V> Deserialize<SecondaryMap<K, V>, __D> for Archived<SecondaryMap<K, V>>where K: EntityRef, V: Clone + Archive, Vec<V>: Archive, Archived<Vec<V>>: Deserialize<Vec<V>, __D>, Archived<V>: Deserialize<V, __D>, PhantomData<K>: Archive, Archived<PhantomData<K>>: Deserialize<PhantomData<K>, __D>,

source§

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

Deserializes using the given deserializer
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<__S: Fallible + ?Sized, K, V> Serialize<__S> for SecondaryMap<K, V>where K: EntityRef, V: Clone + Serialize<__S>, Vec<V>: Serialize<__S>, PhantomData<K>: Serialize<__S>,

source§

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

Writes the dependencies for the object and returns a resolver that can create the archived type.
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> ArchivePointee for T

§

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

§

type Archived = <T as Archive>::Archived

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

type MetadataResolver = ()

The resolver for the metadata of this type. Read more
source§

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

unsafe fn resolve_unsized( &self, from: usize, to: usize, resolver: Self::MetadataResolver, out: *mut RelPtr<Self::Archived, <isize as Archive>::Archived> )

Resolves a relative pointer to this value with the given from and to and writes it to the given output. 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<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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> LayoutRaw for T

source§

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

Gets the layout of the type.
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T, S> SerializeUnsized<S> for Twhere T: Serialize<S>, S: Serializer + ?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§

fn serialize_metadata(&self, _: &mut S) -> Result<(), <S as Fallible>::Error>

Serializes the metadata for the given type.
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.