Trait Collection

Source
pub trait Collection {
    type Entry;
    type Val;

    // Required method
    fn entry_to_val(e: Self::Entry) -> Self::Val;
}
Expand description

Represents a collection by defining the types of entries and values it handles.

This trait abstracts the nature of collections in data structures, facilitating the handling of contained entries and values, especially in scenarios where the structure of the collection allows for complex relationships, such as HashMaps. It not only identifies what constitutes an entry and a value in the context of the collection but also provides utility for converting between these two, which is critical in operations involving entry manipulation and value retrieval.

Required Associated Types§

Source

type Entry

The type of entries that can be added to the collection. This type can differ from Val in collections like HashMap, where an entry might represent a key-value pair, and Val could represent just the value or the key.

Source

type Val

The type of values stored in the collection. This might be distinct from Entry in complex collections. For example, in a HashMap, while Entry might be a ( key, value ) tuple, Val might only be the value part.

Required Methods§

Source

fn entry_to_val(e: Self::Entry) -> Self::Val

Converts an entry to its corresponding value within the collection. This function is essential for abstracting the collection’s internal representation from the values it manipulates.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<E> Collection for BinaryHeap<E>

Source§

impl<E> Collection for BTreeSet<E>

Source§

impl<E> Collection for LinkedList<E>

Source§

impl<E> Collection for VecDeque<E>

Source§

impl<E> Collection for Vec<E>

Source§

impl<K> Collection for HashSet<K>
where K: Eq + Hash,

Source§

impl<K, V> Collection for BTreeMap<K, V>
where K: Ord,

Source§

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

Implementors§