Trait former::exposed::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 HashMap
s, 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§
Required Methods§
sourcefn val_to_entry(val: Val) -> Self::Entry
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)
}
}