Trait geng::prelude::Diff

pub trait Diff: Debug + Serialize + DeserializeOwned + Sync + Send + Clone + PartialEq + 'static + Unpin {
    type Delta: Debug + Serialize + DeserializeOwned + Sync + Send + Clone + 'static + Unpin;

    // Required methods
    fn diff(&self, to: &Self) -> Self::Delta;
    fn update(&mut self, delta: &Self::Delta);
}
Expand description

A diffable type

Can be derived

For Copy types implementation just uses the type itself as delta.

Most of the trait bounds should not be here, but are because of https://github.com/rust-lang/rust/issues/20671

Required Associated Types§

type Delta: Debug + Serialize + DeserializeOwned + Sync + Send + Clone + 'static + Unpin

Object representing the difference between two states of Self

Required Methods§

fn diff(&self, to: &Self) -> Self::Delta

Calculate the difference between two states

fn update(&mut self, delta: &Self::Delta)

Update the state using the delta

let a = 0_i32;
let b = 1_i32;
let delta = Diff::diff(&a, &b);

let mut a = a;
a.update(&delta);
assert_eq!(a, b);

Object Safety§

This trait is not object safe.

Implementors§

§

impl<T> Diff for Collection<T>
where T: HasId + Clone + Diff,

§

impl<T> Diff for T
where T: Debug + Serialize + DeserializeOwned + Sync + Send + Copy + PartialEq + 'static + Unpin,

§

type Delta = T