pub fn apply<C, E>(
target: &mut C,
delta: MapDelta<E::Key, E::Value, <E::Value as Delta>::Output>,
)where
C: IntoIterator<Item = E> + Extend<E> + TryIndexMut<E::Key, Output = E::Value>,
E: MapEntry,
E::Value: Delta,Expand description
Applies a keyed diff to target in place.
Removals and changes are single lookups rather than scans, so this costs
the same as diff does, and a changed value is updated where it sits
rather than taken out and put back. As with an unordered field,
membership is preserved but position is not.
A key in remove or change that target does not have is ignored.
use delta_struct::{map, Delta};
use std::collections::BTreeMap;
#[derive(Delta)]
struct Service {
port: u16,
}
let services = |port| {
vec![("web", Service { port })]
.into_iter()
.collect::<BTreeMap<&str, Service>>()
};
let delta = map::diff(services(80), services(8080));
let mut target = services(80);
map::apply(&mut target, delta);
assert_eq!(target["web"].port, 8080);