1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
mod impls;
#[cfg(test)]
mod tests;
pub mod utils;
pub use diff_derive::Diff;
pub use impls::*;
pub trait Diff: Sized {
type Repr;
fn diff(&self, other: &Self) -> Self::Repr;
fn diff_custom<D: Differ<Self>>(&self, other: &Self, visitor: &D) -> D::Repr {
visitor.diff(self, other)
}
fn apply(&mut self, diff: &Self::Repr);
fn apply_custom<D: Differ<Self>>(&mut self, diff: &D::Repr, visitor: &D) {
visitor.apply(self, diff)
}
fn apply_new(&self, diff: &Self::Repr) -> Self {
let mut new = Self::identity();
new.apply(&new.diff(self));
new.apply(diff);
new
}
fn apply_new_custom<D: Differ<Self>>(&self, diff: &D::Repr, visitor: &D) -> Self {
let mut new = Self::identity();
new.apply_custom(&new.diff_custom(self, visitor), visitor);
new.apply_custom(diff, visitor);
new
}
fn identity() -> Self;
}
pub trait Differ<T> {
type Repr;
fn diff(&self, a: &T, b: &T) -> Self::Repr;
fn apply(&self, a: &mut T, b: &Self::Repr);
}