Collection

Trait Collection 

Source
pub trait Collection<I, T>:
    Any
    + Debug
    + Send {
    // Required methods
    fn get(&self, id: &I) -> Option<&T>;
    fn contains_key(&self, id: &I) -> bool;
    fn len(&self) -> usize;
    fn is_empty(&self) -> bool;
    fn iter(&self) -> Box<dyn Iterator<Item = (&'_ I, &'_ T)> + '_>;
    fn keys(&self) -> Box<dyn Iterator<Item = &'_ I> + '_>;
    fn values(&self) -> Box<dyn Iterator<Item = &'_ T> + '_>;
}
Expand description

Collection of items.

This data type combines the most common traits from our store abstractions into a single trait that is dyn-compatible, so it can be used in operator functions to erase the concrete store type, which is central to hiding the implementation details of operators.

In order to automatically implement the Value trait for all data types that implement Store and friends, we must implement Value on the trait object dyn Collection<I, T>. Thus, we must require the supertraits of Value on this trait, and for the blanket implementation. In case more supertraits are added to Value in the future, we must add them here as well, which is however unlikely to happen.

Required Methods§

Source

fn get(&self, id: &I) -> Option<&T>

Returns a reference to the value identified by the key.

Source

fn contains_key(&self, id: &I) -> 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 iter(&self) -> Box<dyn Iterator<Item = (&'_ I, &'_ T)> + '_>

Creates an iterator over the store.

Source

fn keys(&self) -> Box<dyn Iterator<Item = &'_ I> + '_>

Creates a key iterator over the store.

Source

fn values(&self) -> Box<dyn Iterator<Item = &'_ T> + '_>

Creates a value iterator over the store.

Trait Implementations§

Source§

impl<I, T> Value for dyn Collection<I, T>
where I: Id, T: Value,

Implementors§

Source§

impl<I, T, S> Collection<I, T> for S
where I: Id, T: Value, S: Any + Debug + Send + Store<I, T> + StoreIterable<I, T> + StoreKeys<I, T> + StoreValues<I, T>,