VecMap

Struct VecMap 

Source
pub struct VecMap<K: Eq, V: Sized + PartialEq> { /* private fields */ }
Expand description

A map type backed by a Vector. Useful for small collections whose size can change.

Implementations§

Source§

impl<K: Eq, V: Sized + PartialEq> VecMap<K, V>

Source

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

Creates a new, empty VecMap. Calls Vec::new() internally.

Source

pub const unsafe fn from_vec_unchecked(vector: Vec<(K, V)>) -> VecMap<K, V>

Please only use this method to create map literals if the “macros” feature is unavailable to you “macros” provides safe, checked alternatives to initialize linear maps with compile time checking of the invariants of each type.

Creates a new VecMap from the supplied vector.

SAFETY: improper use of this method - initializing with duplicate keys - will NOT create memory unsafety, but will result in every identical key beyond the first never getting accessed as LinearMaps short circuit on the first matching key.

Source

pub fn len(&self) -> usize

Returns the number of elements in the container

Source

pub fn is_empty(&self) -> bool

Returns true if the store is empty, false otherwise.

Source

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

Creates a new, empty VecMap with capacity set to the provide value. Calls Vec::with_capacity() internally.

Source

pub fn remove(&mut self, key: &K) -> Option<V>

Tries to remove the value associated with the given key, returning None if it is not found.

Source

pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)>

Tries to remove the entry associated with the given key, returning None if it is not found.

Source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Inserts the provided value into the VecMap. If the provided key is found it will update the value. and return the old value. If not, this will allocate for a new key value pair.

Trait Implementations§

Source§

impl<K: Clone + Eq, V: Clone + Sized + PartialEq> Clone for VecMap<K, V>

Source§

fn clone(&self) -> VecMap<K, V>

Returns a duplicate 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: Debug + Eq, V: Debug + Sized + PartialEq> Debug for VecMap<K, V>

Source§

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

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

impl<K: Default + Eq, V: Default + Sized + PartialEq> Default for VecMap<K, V>

Source§

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

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

impl<K: Hash + Eq, V: Hash + Sized + PartialEq> Hash for VecMap<K, V>

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: Eq, V: Sized + PartialEq> LinearMap<K, V> for VecMap<K, V>

Source§

type Backing = Vec<(K, V)>

Source§

fn as_slice(&self) -> &[(K, V)]

The keys and values of the map.
Source§

fn into_inner(self) -> Self::Backing

Consumes self, returning the underlying store.
Source§

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

Returns true if this map contains the given key. False otherwise.
Source§

fn contains_value(&self, value: &V) -> bool

Returns true if this map contains a given value. False otherwise.
Source§

fn get<'a>(&'a self, key: &'a K) -> Option<&'a V>

Gets a reference with the associated key. Will return None if that i key is not in the map.
Source§

fn get_mut<'a>(&'a mut self, key: &'a K) -> Option<&'a mut V>

Gets a mutable reference with the associated key. Will return None if that key is not in the map.
Source§

fn nth_value<'a>(&'a self, index: usize) -> Option<&'a V>
where K: 'a,

Gets a reference to the nth value in the map. Will return None if index is out of bounds.
Source§

fn nth_value_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut V>
where K: 'a,

Gets a reference to the nth value in the map. Will return None if index is out of bounds.
Source§

fn nth_key<'a>(&'a self, index: usize) -> Option<&'a K>
where V: 'a,

Gets a reference to the nth value in the map. Will return None if index is out of bounds.
Source§

fn nth_key_mut<'a>(&'a mut self, index: usize) -> Option<&'a mut K>
where V: 'a,

Gets a reference to the nth key in the map. Will return None if index is out of bounds.
Source§

fn replace(&mut self, key: &K, value: V)

Searches for a key == key in the map. If it is present replaces its value with “value”. If not, it does nothing.
Source§

fn merge_from_iter<'a>(&'a mut self, iter: impl Iterator<Item = &'a (K, V)>)
where K: 'a, V: 'a + Clone,

For every key in iter which matches a key in self, this method replaces the value from iter in self, “merging” the iterator and the map. Read more
Source§

impl<K: Ord + Eq, V: Ord + Sized + PartialEq> Ord for VecMap<K, V>

Source§

fn cmp(&self, other: &VecMap<K, V>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<K: PartialEq + Eq, V: PartialEq + Sized + PartialEq> PartialEq for VecMap<K, V>

Source§

fn eq(&self, other: &VecMap<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<K: PartialOrd + Eq, V: PartialOrd + Sized + PartialEq> PartialOrd for VecMap<K, V>

Source§

fn partial_cmp(&self, other: &VecMap<K, V>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<K: Eq + Eq, V: Eq + Sized + PartialEq> Eq for VecMap<K, V>

Source§

impl<K: Eq, V: Sized + PartialEq> StructuralPartialEq for VecMap<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for VecMap<K, V>

§

impl<K, V> RefUnwindSafe for VecMap<K, V>

§

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

§

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

§

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

§

impl<K, V> UnwindSafe for VecMap<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> 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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> 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.