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§
Sourcefn contains_key(&self, id: &K) -> bool
fn contains_key(&self, id: &K) -> bool
Returns whether the collection contains the key.
Sourcefn remove_entry(&mut self, key: &K) -> Option<(K, V)>
fn remove_entry(&mut self, key: &K) -> Option<(K, V)>
Removes the value identified by the key and returns both.
Implementations§
Source§impl<K, V> dyn Collection<K, V>
impl<K, V> dyn Collection<K, V>
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: Collection<K, V> + Any,
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: Collection<K, V> + Any,
Attempts to downcast to a reference of T.
Sourcepub fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: Collection<K, V> + Any,
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.