[][src]Trait diff::Diff

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 { ... } }

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

Associated Types

type Repr

The type associated with the structs' difference

Loading content...

Required methods

fn diff(&self, other: &Self) -> Self::Repr

Produces a diff between two structs

fn apply(&mut self, diff: &Self::Repr)

Applies the diff directly to the struct

fn identity() -> Self

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

Loading content...

Provided methods

fn diff_custom<D: Differ<Self>>(&self, other: &Self, visitor: &D) -> D::Repr

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

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

fn apply_new(&self, diff: &Self::Repr) -> Self

Applies the diff to the struct and produces a new struct

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

Loading content...

Implementations on Foreign Types

impl Diff for bool[src]

type Repr = Option<bool>

impl Diff for u8[src]

type Repr = u8

impl Diff for i8[src]

type Repr = i8

impl Diff for u16[src]

type Repr = u16

impl Diff for i16[src]

type Repr = i16

impl Diff for u32[src]

type Repr = u32

impl Diff for i32[src]

type Repr = i32

impl Diff for u64[src]

type Repr = u64

impl Diff for i64[src]

type Repr = i64

impl Diff for usize[src]

type Repr = usize

impl Diff for isize[src]

type Repr = isize

impl Diff for f32[src]

type Repr = f32

impl Diff for f64[src]

type Repr = f64

impl Diff for char[src]

type Repr = Option<char>

impl Diff for String[src]

type Repr = Option<String>

impl<T: Diff + PartialEq> Diff for Option<T>[src]

type Repr = OptionDiff<T>

impl<K: Hash + Eq, V: Diff> Diff for HashMap<K, V> where
    K: Clone,
    V: PartialEq
[src]

type Repr = HashMapDiff<K, V>

impl<T: Diff + PartialEq> Diff for Vec<T>[src]

type Repr = VecDiff<T>

Loading content...

Implementors

Loading content...