pub struct VecMap<K, V>(Vec<(K, V)>);
Expand description

A map type implemented as a vector of pairs K (key) and V (value). It currently provides a subset of all the map operations, the rest could be added as needed.

Tuple Fields§

§0: Vec<(K, V)>

Implementations§

source§

impl<K, V> VecMap<K, V>where K: Debug + PartialEq, V: Debug,

source

pub fn new() -> Self

source

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

Sets the value of the entry, and returns the entry’s old value.

source

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

Removes the entry from the map and returns the removed value

source

pub fn get<Q>(&self, k: &Q) -> Option<&V>where K: Borrow<Q>, Q: Eq + ?Sized,

Gets a reference to the value in the entry.

source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>where K: Borrow<Q>, Q: Eq + ?Sized,

Gets a mutable reference to the value in the entry.

source

pub fn any_value_matching( &self, predicate: impl FnMut(&(K, V)) -> bool ) -> Option<&V>

Returns the any value corresponding to the supplied predicate filter.

The supplied predicate will be applied to each (key, value) pair and it will return a reference to the values where the predicate returns true.

source

pub fn get_value_matching( &self, predicate: impl FnMut(&(K, V)) -> bool ) -> Option<&V>

Returns the value corresponding to the supplied predicate filter. It crashes if there’s more than one matching element.

The supplied predicate will be applied to each (key, value) pair and it will return a reference to the value where the predicate returns true.

source

pub fn contains_key<Q>(&self, k: &Q) -> boolwhere K: Borrow<Q>, Q: Eq + ?Sized,

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, Eq on the borrowed form must match those for the key type.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source

pub fn iter(&self) -> Iter<'_, (K, V)> ⓘ

source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>

source

pub fn retain(&mut self, f: impl Fn(&(K, V)) -> bool)

Trait Implementations§

source§

impl<K: Clone, V: Clone> Clone for VecMap<K, V>

source§

fn clone(&self) -> VecMap<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: Debug, V: Debug> 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, V, __D: Decoder> Decodable<__D> for VecMap<K, V>where K: Decodable<__D>, V: Decodable<__D>,

source§

fn decode(__decoder: &mut __D) -> Self

source§

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

source§

fn default() -> Self

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

impl<K, V, __E: Encoder> Encodable<__E> for VecMap<K, V>where K: Encodable<__E>, V: Encodable<__E>,

source§

fn encode(&self, __encoder: &mut __E)

source§

impl<K: PartialEq + Debug, V: Debug> Extend<(K, V)> for VecMap<K, V>

source§

fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, (k, v): (K, V))

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<K, V> From<Vec<(K, V), Global>> for VecMap<K, V>

source§

fn from(vec: Vec<(K, V)>) -> Self

Converts to this type from the input type.
source§

impl<K, V> FromIterator<(K, V)> for VecMap<K, V>

source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<K, V, CTX> HashStable<CTX> for VecMap<K, V>where K: HashStable<CTX> + Eq, V: HashStable<CTX>,

source§

fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)

source§

impl<K, V> Into<Vec<(K, V), Global>> for VecMap<K, V>

source§

fn into(self) -> Vec<(K, V)>

Converts this type into the (usually inferred) input type.
source§

impl<'a, K, V> IntoIterator for &'a VecMap<K, V>

§

type Item = &'a (K, V)

The type of the elements being iterated over.
§

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: 'a, V: 'a> IntoIterator for &'a mut VecMap<K, V>

§

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

The type of the elements being iterated over.
§

type IntoIter = impl Iterator<Item = (&'a K, &'a mut 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 VecMap<K, V>

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<(K, V), Global>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

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

§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 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.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<'a, T> Captures<'a> for Twhere T: ?Sized,

source§

impl<T> Erased for T

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 24 bytes