pub fn diff<C, E>(old: C, new: C) -> EntryDelta<E::Key, E::Value>Expand description
Pairs the entries of old and new by key and records what the keys that
survived hold now.
Returns an empty EntryDelta when the two hold the same entries. Each
key of old is looked up in new exactly once, through the collection’s
own TryIndex implementation, so the cost is that of n lookups: O(n) for
a HashMap, O(n log n) for a
BTreeMap.
use delta_struct::entry::diff;
use std::collections::BTreeMap;
let labels = |tier: &'static str| {
vec![("tier", tier)].into_iter().collect::<BTreeMap<&str, &str>>()
};
let delta = diff(labels("web"), labels("edge"));
// The key survived, so only what it holds now travels — the old value
// stays where it is, on the receiver.
assert_eq!(delta.add, vec![("tier", "edge")]);
assert!(delta.remove.is_empty());