Struct linear_collections::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 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 len(&self) -> usize

Returns the number of entries in the map

source

pub fn is_empty(&self) -> bool

Returns true if the store is empty, false otherwise.

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

§

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.

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> 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, U> TryFrom<U> for T
where 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 T
where 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.