pub fn apply<C, E>(target: &mut C, delta: EntryDelta<E::Key, E::Value>)Expand description
Applies a keyed membership diff to target in place.
Each removal is a single lookup rather than a scan, so this costs the same
as diff does. Membership is preserved but position is not — additions
land wherever the collection decides to put them. Use ordered where that
matters.
A removal naming a key that target does not have is ignored, and an
addition overwrites whatever the key held, which together make applying the
same delta twice harmless.
use delta_struct::entry::{apply, diff};
use std::collections::BTreeMap;
let labels = |entries: Vec<(&'static str, &'static str)>| {
entries.into_iter().collect::<BTreeMap<&str, &str>>()
};
let delta = diff(
labels(vec![("tier", "web"), ("zone", "a")]),
labels(vec![("tier", "edge")]),
);
let mut target = labels(vec![("tier", "web"), ("zone", "a")]);
apply(&mut target, delta);
assert_eq!(target, labels(vec![("tier", "edge")]));