Skip to main content

Collection

Trait Collection 

Source
pub trait Collection<K, V>: Any + Debug {
    // Required methods
    fn get(&self, key: &K) -> Option<&V>;
    fn contains_key(&self, id: &K) -> bool;
    fn len(&self) -> usize;
    fn is_empty(&self) -> bool;
    fn insert(&mut self, key: K, value: V) -> Option<V>;
    fn remove(&mut self, key: &K) -> Option<V>;
    fn remove_entry(&mut self, key: &K) -> Option<(K, V)>;
    fn clear(&mut self);
    fn iter(&self) -> Iter<'_, K, V>;
    fn keys(&self) -> Keys<'_, K>;
    fn values(&self) -> Values<'_, V>;
}
Expand description

Collection.

This trait combines the following traits, which are not dyn-compatible for reasons of flexibility, into a single trait object that allows to erase the type of the underlying store while preserving the types of the key and value type parameters, K and V:

Additionally, implementors must implement Any, so a Collection can be downcast to an immutable or mutable reference of its concrete type, if necessary and known, as well as Debug, in order to conveniently print the contents of the collection.

We also provide a blanket implementation for implementors which fulfill all of the aforementioned traits, so that they can be used as a Collection.

Required Methods§

Source

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

Returns a reference to the value identified by the key.

Source

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

Returns whether the collection contains the key.

Source

fn len(&self) -> usize

Returns the number of items in the collection.

Source

fn is_empty(&self) -> bool

Returns whether the collection is empty.

Source

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

Inserts the value identified by the key.

Source

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

Removes the value identified by the key.

Source

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

Removes the value identified by the key and returns both.

Source

fn clear(&mut self)

Clears the collection, removing all items.

Source

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

Creates an iterator over the items of the collection.

Source

fn keys(&self) -> Keys<'_, K>

Creates an iterator over the keys of the collection.

Source

fn values(&self) -> Values<'_, V>

Creates an iterator over the values of the collection.

Implementations§

Source§

impl<K, V> dyn Collection<K, V>

Source

pub fn downcast_ref<T>(&self) -> Option<&T>
where T: Collection<K, V> + Any,

Attempts to downcast to a reference of T.

Source

pub fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: Collection<K, V> + Any,

Attempts to downcast to a mutable reference of T.

Trait Implementations§

Source§

impl<'a, K, V> IntoIterator for &'a dyn Collection<K, V>
where K: Key, V: Value,

Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator over the items of the collection.

Source§

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

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = (&'a K, &'a V)> + 'a>

Which kind of iterator are we turning this into?

Implementors§

Source§

impl<K, V, S> Collection<K, V> for S
where K: Key, V: Value, S: Any + Debug + Store<K, V> + StoreMut<K, V> + StoreIterable<K, V> + StoreKeys<K, V> + StoreValues<K, V>,