Trait former::exposed::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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<E> Collection for BinaryHeap<E>

§

type Entry = E

§

type Val = E

source§

fn entry_to_val( e: <BinaryHeap<E> as Collection>::Entry ) -> <BinaryHeap<E> as Collection>::Val

source§

impl<E> Collection for BTreeSet<E>

§

type Entry = E

§

type Val = E

source§

fn entry_to_val( e: <BTreeSet<E> as Collection>::Entry ) -> <BTreeSet<E> as Collection>::Val

source§

impl<E> Collection for LinkedList<E>

§

type Entry = E

§

type Val = E

source§

fn entry_to_val( e: <LinkedList<E> as Collection>::Entry ) -> <LinkedList<E> as Collection>::Val

source§

impl<E> Collection for VecDeque<E>

§

type Entry = E

§

type Val = E

source§

fn entry_to_val( e: <VecDeque<E> as Collection>::Entry ) -> <VecDeque<E> as Collection>::Val

source§

impl<E> Collection for Vec<E>

§

type Entry = E

§

type Val = E

source§

fn entry_to_val(e: <Vec<E> as Collection>::Entry) -> <Vec<E> as Collection>::Val

source§

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

§

type Entry = K

§

type Val = K

source§

fn entry_to_val( e: <HashSet<K> as Collection>::Entry ) -> <HashSet<K> as Collection>::Val

source§

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

§

type Entry = (K, V)

§

type Val = V

source§

fn entry_to_val( e: <BTreeMap<K, V> as Collection>::Entry ) -> <BTreeMap<K, V> as Collection>::Val

source§

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

§

type Entry = (K, V)

§

type Val = V

source§

fn entry_to_val( e: <HashMap<K, V> as Collection>::Entry ) -> <HashMap<K, V> as Collection>::Val

Implementors§