Trait diff::Diff

source ·
pub trait Diff: Sized {
    type Repr;

    fn diff(&self, other: &Self) -> Self::Repr;
    fn apply(&mut self, diff: &Self::Repr);
    fn identity() -> Self;

    fn diff_custom<D: Differ<Self>>(&self, other: &Self, visitor: &D) -> D::Repr { ... }
    fn apply_custom<D: Differ<Self>>(&mut self, diff: &D::Repr, visitor: &D) { ... }
    fn apply_new(&self, diff: &Self::Repr) -> Self { ... }
    fn apply_new_custom<D: Differ<Self>>(
        &self,
        diff: &D::Repr,
        visitor: &D
    ) -> Self { ... } }
Expand description

A trait to diff and apply diffs between two structs The derive macro can be used on structs when all fields of the struct implement Diff Implementations are provided for bools, numeric types, Option types, and HashMaps

Required Associated Types§

The type associated with the structs’ difference

Required Methods§

Produces a diff between two structs

Applies the diff directly to the struct

The identity element of the struct

use diff::Diff;
let s = 42;
let i = <i32 as Diff>::identity();
assert_eq!(i.apply_new(&i.diff(&s)), s);

or mathematically speaking, i + (s - i) = s

Provided Methods§

Produces a diff between two structs, using an external diffing implementation

Applies the diff directly to the struct, using an external diffing implementation

Applies the diff to the struct and produces a new struct

Applies the diff to the struct and produces a new struct, using an external diffing implementation

Implementations on Foreign Types§

Implementors§