pub trait Delta {
type Output;
// Required methods
fn delta(old: Self, new: Self) -> Option<Self::Output>;
fn apply_delta(&mut self, delta: Self::Output);
}Expand description
Computing the difference between two values, and applying it to a third.
You will normally derive this rather than implement it — see the
crate documentation for the derive’s attributes and the shape of
the type it generates. Implement it by hand when you want custom diffing
for a type that other structs then reference with
#[delta_struct(field_type = "delta")].
Required Associated Types§
Required Methods§
Sourcefn delta(old: Self, new: Self) -> Option<Self::Output>
fn delta(old: Self, new: Self) -> Option<Self::Output>
Computes what it would take to turn old into new.
Returns None when the two are equivalent, which lets callers skip
sending or storing an update that would do nothing. Both values are
consumed: the delta takes ownership of whatever it needs from new.
Sourcefn apply_delta(&mut self, delta: Self::Output)
fn apply_delta(&mut self, delta: Self::Output)
Applies a delta in place.
Applying the delta from delta(old, new) to a value equal to old
yields a value equal to new — with the caveat that unordered fields
preserve membership rather than order.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".