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
//! Implementation of [`Map`] for a [`BTreeMap`].
use std::collections::BTreeMap;

use crate::Map;

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