pub trait Diff: Sized {
type Repr;
// Required methods
fn diff(&self, other: &Self) -> Self::Repr;
fn apply(&mut self, diff: &Self::Repr);
fn identity() -> Self;
// Provided methods
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§
Required Methods§
Provided Methods§
Sourcefn diff_custom<D: Differ<Self>>(&self, other: &Self, visitor: &D) -> D::Repr
fn diff_custom<D: Differ<Self>>(&self, other: &Self, visitor: &D) -> D::Repr
Produces a diff between two structs, using an external diffing implementation
Sourcefn apply_custom<D: Differ<Self>>(&mut self, diff: &D::Repr, visitor: &D)
fn apply_custom<D: Differ<Self>>(&mut self, diff: &D::Repr, visitor: &D)
Applies the diff directly to the struct, using an external diffing implementation
Sourcefn apply_new(&self, diff: &Self::Repr) -> Self
fn apply_new(&self, diff: &Self::Repr) -> Self
Applies the diff to the struct and produces a new struct
Sourcefn apply_new_custom<D: Differ<Self>>(&self, diff: &D::Repr, visitor: &D) -> Self
fn apply_new_custom<D: Differ<Self>>(&self, diff: &D::Repr, visitor: &D) -> Self
Applies the diff to the struct and produces a new struct, using an external diffing implementation
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Diff for NonZeroU16
impl Diff for NonZeroU16
Source§impl Diff for NonZeroU32
impl Diff for NonZeroU32
Source§impl Diff for NonZeroU64
impl Diff for NonZeroU64
Source§impl Diff for NonZeroU128
impl Diff for NonZeroU128
Source§impl Diff for NonZeroUsize
impl Diff for NonZeroUsize
Source§impl<A, B, C, D> Diff for (A, B, C, D)
impl<A, B, C, D> Diff for (A, B, C, D)
Source§impl<A, B, C, D, F> Diff for (A, B, C, D, F)
impl<A, B, C, D, F> Diff for (A, B, C, D, F)
Source§impl<A, B, C, D, F, G> Diff for (A, B, C, D, F, G)
impl<A, B, C, D, F, G> Diff for (A, B, C, D, F, G)
Source§impl<A, B, C, D, F, G, H> Diff for (A, B, C, D, F, G, H)
impl<A, B, C, D, F, G, H> Diff for (A, B, C, D, F, G, H)
Source§impl<A, B, C, D, F, G, H, I> Diff for (A, B, C, D, F, G, H, I)
impl<A, B, C, D, F, G, H, I> Diff for (A, B, C, D, F, G, H, I)
Source§impl<A, B, C, D, F, G, H, I, J> Diff for (A, B, C, D, F, G, H, I, J)
impl<A, B, C, D, F, G, H, I, J> Diff for (A, B, C, D, F, G, H, I, J)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K> Diff for (A, B, C, D, F, G, H, I, J, K)
impl<A, B, C, D, F, G, H, I, J, K> Diff for (A, B, C, D, F, G, H, I, J, K)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L> Diff for (A, B, C, D, F, G, H, I, J, K, L)
impl<A, B, C, D, F, G, H, I, J, K, L> Diff for (A, B, C, D, F, G, H, I, J, K, L)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L, M> Diff for (A, B, C, D, F, G, H, I, J, K, L, M)
impl<A, B, C, D, F, G, H, I, J, K, L, M> Diff for (A, B, C, D, F, G, H, I, J, K, L, M)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr, <M as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L, M, N> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N)
impl<A, B, C, D, F, G, H, I, J, K, L, M, N> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr, <M as Diff>::Repr, <N as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O)
impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr, <M as Diff>::Repr, <N as Diff>::Repr, <O as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P)
impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr, <M as Diff>::Repr, <N as Diff>::Repr, <O as Diff>::Repr, <P as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q)
impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr, <M as Diff>::Repr, <N as Diff>::Repr, <O as Diff>::Repr, <P as Diff>::Repr, <Q as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R)
impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr, <M as Diff>::Repr, <N as Diff>::Repr, <O as Diff>::Repr, <P as Diff>::Repr, <Q as Diff>::Repr, <R as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R, S> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)
impl<A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R, S> Diff for (A, B, C, D, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)
type Repr = (<A as Diff>::Repr, <B as Diff>::Repr, <C as Diff>::Repr, <D as Diff>::Repr, <F as Diff>::Repr, <G as Diff>::Repr, <H as Diff>::Repr, <I as Diff>::Repr, <J as Diff>::Repr, <K as Diff>::Repr, <L as Diff>::Repr, <M as Diff>::Repr, <N as Diff>::Repr, <O as Diff>::Repr, <P as Diff>::Repr, <Q as Diff>::Repr, <R as Diff>::Repr, <S as Diff>::Repr)
fn diff(&self, other: &Self) -> Self::Repr
fn apply(&mut self, diff: &Self::Repr)
fn identity() -> Self
Source§impl<T> Diff for Cow<'_, T>
impl<T> Diff for Cow<'_, T>
Source§type Repr = Option<<T as ToOwned>::Owned>
type Repr = Option<<T as ToOwned>::Owned>
Note: This was done to make sure a diff is able to outlive its sources, which is the most desirable outcome if the diff is to be moved around and consumed much later (or even serialized into foreign programs)