Trait structdiff::StructDiff
source · pub trait StructDiff: PartialEq + Sized {
type Diff;
fn diff(&self, updated: &Self) -> Vec<Self::Diff>;
fn apply_single(&mut self, diff: Self::Diff);
fn apply(self, diffs: Vec<Self::Diff>) -> Self { ... }
fn apply_ref(&self, diffs: Vec<Self::Diff>) -> Self
where
Self: Clone,
{ ... }
fn apply_mut(&mut self, diffs: Vec<Self::Diff>) { ... }
}Required Associated Types§
Required Methods§
sourcefn diff(&self, updated: &Self) -> Vec<Self::Diff>
fn diff(&self, updated: &Self) -> Vec<Self::Diff>
Generate a diff between two instances of a struct. This diff may be serialized if one of the serialization features is enabled.
use structdiff::{Difference, StructDiff};
#[derive(Debug, PartialEq, Clone, Difference)]
struct Example {
field1: f64,
}
let first = Example {
field1: 0.0,
};
let second = Example {
field1: 3.14,
};
let diffs = first.diff(&second);
let diffed = first.apply(diffs);
assert_eq!(diffed, second);sourcefn apply_single(&mut self, diff: Self::Diff)
fn apply_single(&mut self, diff: Self::Diff)
Apply a single-field diff to a mutable self ref