aggregate-map 1.0.1

Collect key-values pairs into a mapping from keys to collections of values.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//! Implementation of [`Map`] for a [`HashMap`].
use std::collections::HashMap;

use crate::Map;

impl<K, V, C, S> Map<K, V> for HashMap<K, C, S>
where
    K: Eq + std::hash::Hash,
    C: Default + Extend<V>,
    S: std::hash::BuildHasher,
{
    fn insert(&mut self, key: K, value: V) {
        self.entry(key).or_default().extend(std::iter::once(value));
    }
}