Trait former::exposed::orphan::CollectionValToEntry

source ·
pub trait CollectionValToEntry<Val> {
    type Entry;

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

Provides a mechanism for transforming a value back into a collection-specific entry format.

This trait is particularly valuable in scenarios where the operations on a collection require not just the manipulation of values but also the re-integration of these values as entries. It is especially crucial in complex data structures, such as HashMaps, where entries often involve a key-value pair, and simple values need to be restructured to fit this model for operations like insertion or update.

Required Associated Types§

source

type Entry

The specific type of entry that corresponds to the value within the collection. For example, in a HashMap, this might be a tuple of a key and a value.

Required Methods§

source

fn val_to_entry(val: Val) -> Self::Entry

Converts a value into a collection-specific entry, facilitating operations that modify the collection. This method is key for ensuring that values can be correctly integrated back into the collection, particularly when the entry type is more complex than the value.

§Parameters
  • val - The value to be converted into an entry.
§Returns

Returns the entry constructed from the provided value, ready for insertion or other modifications.

§Example
use former_types::CollectionValToEntry; // use crate `former` instead of crate `former_types` unless you need to use crate `former_types` directly

struct PairMap;

impl CollectionValToEntry< ( i32, i32 ) > for PairMap
{
  type Entry = ( String, i32 );

  fn val_to_entry( val : ( i32, i32 ) ) -> Self::Entry
  {
    (val.0.to_string(), val.1)
  }
}

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<E> CollectionValToEntry<E> for BinaryHeap<E>

source§

impl<E> CollectionValToEntry<E> for BTreeSet<E>

source§

impl<E> CollectionValToEntry<E> for LinkedList<E>

source§

impl<E> CollectionValToEntry<E> for VecDeque<E>

source§

impl<E> CollectionValToEntry<E> for Vec<E>

§

type Entry = E

source§

fn val_to_entry(val: E) -> <Vec<E> as CollectionValToEntry<E>>::Entry

source§

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

Implementors§