Trait batbox_diff::Diff

source ·
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§

source

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

Object representing the difference between two states of Self

Required Methods§

source

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

Calculate the difference between two states

source

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);

Implementors§

source§

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

§

type Delta = T