pub struct VecMap<K, V>(/* private fields */);Expand description
An mapping of key/value pairs stored as pairs ordered by their key in a Vec.
This is always efficient for small sizes of mappings, and efficient for large sizes when insertion is not needed (i.e. items are placed into the mapping in bulk).
Implementations§
Source§impl<K: Eq + PartialEq + Ord + PartialOrd, V> VecMap<K, V>
impl<K: Eq + PartialEq + Ord + PartialOrd, V> VecMap<K, V>
Sourcepub fn iter(&self) -> Iter<'_, (K, V)>
pub fn iter(&self) -> Iter<'_, (K, V)>
Return an iterator over the key/value pairs in this mapping in order.
Sourcepub fn keys(&self) -> impl Iterator<Item = &K>
pub fn keys(&self) -> impl Iterator<Item = &K>
Return an iterator over the keys in this mapping in order.
Sourcepub fn values(&self) -> impl Iterator<Item = &V>
pub fn values(&self) -> impl Iterator<Item = &V>
Return an iterator over the values in this mapping in order of their corresponding key.
Sourcepub fn get(&self, k: &K) -> Option<&V>
pub fn get(&self, k: &K) -> Option<&V>
Get the value of the pair with a particular key.
Returns a reference the value of the item in the mapping whose key equals k.
Sourcepub fn get_mut(&mut self, k: &K) -> Option<&mut V>
pub fn get_mut(&mut self, k: &K) -> Option<&mut V>
Get a mutable reference to the value of the pair with a particular key.
Returns a mutable reference the value of the item in the mapping whose key equals k.
Sourcepub fn to_vec(&self) -> Vec<(K, V)>
pub fn to_vec(&self) -> Vec<(K, V)>
Return a Vec of sorted key/value pairs by cloning this mapping.
Sourcepub fn into_vec(self) -> Vec<(K, V)>
pub fn into_vec(self) -> Vec<(K, V)>
Return the Vec of sorted key/value pairs by consuming this mapping.
Sourcepub fn insert(&mut self, k: K, v: V) -> Option<(K, V)>
pub fn insert(&mut self, k: K, v: V) -> Option<(K, V)>
Insert pair into the mapping.
Inserts some pair (k, v) into the mapping, replacing the existing pair whose key is k,
if any.
Returns Some value which was replaced, if any.
NOTE: This does an ordered insert and thus is slow. If you’re inserting multiple items, use Self::extend which is much more efficient or consider using an alternative data structure if you’re doing this a lot.
Sourcepub fn extend(&mut self, iter: impl IntoIterator<Item = (K, V)>)
pub fn extend(&mut self, iter: impl IntoIterator<Item = (K, V)>)
Insert multiple pairs from an iterator.
Replaces any existing pairs which share a key with an element of the iterator.
Sourcepub fn contains_key(&self, k: &K) -> bool
pub fn contains_key(&self, k: &K) -> bool
Check if a key is in the mapping.
Returns true iff the mapping contains a pair whose key equals k.
Sourcepub fn remove(&mut self, k: &K) -> Option<(K, V)>
pub fn remove(&mut self, k: &K) -> Option<(K, V)>
Remove an item from the mapping by key.
Removes the item with key equal to k from the mapping.
Returns the value of the item removed, if any.
Sourcepub fn retain(&mut self, f: impl FnMut(&K, &V) -> bool)
pub fn retain(&mut self, f: impl FnMut(&K, &V) -> bool)
Filter items from the mapping.
Removes all pairs from the mapping for which f returns false.
Sourcepub fn is_disjoint(&self, other: &VecMap<K, V>) -> boolwhere
V: Ord,
pub fn is_disjoint(&self, other: &VecMap<K, V>) -> boolwhere
V: Ord,
Compares the pairs in two mappings.
Returns true iff every pair in the mapping is not found in other.
Sourcepub fn keys_disjoint<W>(&self, other: &VecMap<K, W>) -> bool
pub fn keys_disjoint<W>(&self, other: &VecMap<K, W>) -> bool
Compares the keys in two mappings.
Returns true iff every key in the mapping is not found in the keys of other.
Sourcepub fn keys_disjoint_with_set(&self, other: &VecSet<K>) -> bool
pub fn keys_disjoint_with_set(&self, other: &VecSet<K>) -> bool
Compares the keys in this mapping with the values in a set.
Returns true iff every key in the mapping is not found in other.
Trait Implementations§
Source§impl<K: Decode + Eq + PartialEq + Ord + PartialOrd, V: Decode> Decode for VecMap<K, V>
impl<K: Decode + Eq + PartialEq + Ord + PartialOrd, V: Decode> Decode for VecMap<K, V>
Source§fn decode<I: Input>(input: &mut I) -> Result<Self, DecodeError>
fn decode<I: Input>(input: &mut I) -> Result<Self, DecodeError>
Source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Source§impl<K, V> Encode for VecMap<K, V>
impl<K, V> Encode for VecMap<K, V>
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
Source§fn encode_to<__CodecOutputEdqy: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Source§fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>(
&self,
f: __CodecUsingEncodedCallback,
) -> __CodecOutputReturn
fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Source§impl<K: Eq + PartialEq + Ord + PartialOrd, V> Extend<(K, V)> for VecMap<K, V>
impl<K: Eq + PartialEq + Ord + PartialOrd, V> Extend<(K, V)> for VecMap<K, V>
Source§fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)