from_entries

Function from_entries 

Source
pub fn from_entries<K, V>(entries: &[Entry<K, V>]) -> HashMap<K, V>
where K: Clone + Eq + Hash, V: Clone,
Expand description

Constructs a HashMap from a slice of Entry structs.

Iterates over each Entry in the provided slice and inserts them into a new HashMap. If duplicate keys are present, the value from the last Entry with that key will be used.

§Arguments

  • entries - A slice of Entry structs to convert into a HashMap.

§Returns

  • HashMap<K, V> - A new HashMap containing all key-value pairs from the entries slice.

§Examples

use lowdash::{Entry, from_entries};
use std::collections::HashMap;

let entries = vec![
    Entry { key: "a", value: 1 },
    Entry { key: "b", value: 2 },
];

let result = from_entries(&entries);
let mut expected = HashMap::new();
expected.insert("a", 1);
expected.insert("b", 2);

assert_eq!(result.len(), expected.len());
for (key, value) in &expected {
   assert_eq!(result.get(key), Some(value));
}