to_pairs

Function to_pairs 

Source
pub fn to_pairs<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.

This function is an alias for the entries function and provides the same functionality. It exists for semantic clarity in contexts where representing map entries as pairs is more intuitive.

§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, to_pairs};
use std::collections::HashMap;

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

let result = to_pairs(&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);