pub trait KeyedCollection: Collection<Item = (Self::Key, Self::Value)> {
    type Key: Eq + Hash;
    type Value;

    // Required methods
    fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>;
    fn insert(
        &mut self,
        key: Self::Key,
        value: Self::Value
    ) -> Option<Self::Value>;
    fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>;
}
Expand description

Trait implemented by key-value maps which need to support collection confinement.

Required Associated Types§

source

type Key: Eq + Hash

Key type for the collection.

source

type Value

Value type for the collection.

Required Methods§

source

fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>

Gets mutable element of the collection

source

fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>

Inserts a new value under a key. Returns previous value if a value under the key was already present in the collection.

source

fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>

Removes a value stored under a given key, returning the owned value, if it was in the collection.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<K: Eq + Hash, V> KeyedCollection for HashMap<K, V>

§

type Key = K

§

type Value = V

source§

fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>

source§

fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>

source§

fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>

source§

impl<K: Ord + Hash, V> KeyedCollection for BTreeMap<K, V>

§

type Key = K

§

type Value = V

source§

fn get_mut(&mut self, key: &Self::Key) -> Option<&mut Self::Value>

source§

fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>

source§

fn remove(&mut self, key: &Self::Key) -> Option<Self::Value>

Implementors§