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§

A generated type used to represent the difference between two instances of a struct which implements the StructDiff trait.

Required Methods§

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);

Apply a single-field diff to a mutable self ref

Provided Methods§

Apply a full diff to an owned self

Apply a full diff to a self ref, returning a cloned version of self after diff is applied

Apply a full diff to a mutable self ref

Implementors§