entries

Function entries 

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

Collects all entries from a map into a vector of Entry structs.

Iterates over each key-value pair in the input map and collects them into a vector.

§Arguments

  • map - The input map from which to collect entries.

§Returns

  • Vec<Entry<K, V>> - A vector containing all key-value pairs as Entry structs.

§Examples

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

let mut map = HashMap::new();
map.insert("a", 1);
map.insert("b", 2);

let result = entries(&map);
let expected = vec![
    Entry { key: "a", value: 1 },
    Entry { key: "b", value: 2 },
];

let mut sorted_result = result.clone();
sorted_result.sort_by(|a, b| a.key.cmp(&b.key));

let mut sorted_expected = expected.clone();
sorted_expected.sort_by(|a, b| a.key.cmp(&b.key));

assert_eq!(sorted_result, sorted_expected);