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

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.

Implementors§

Source§

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

Source§

type Delta = T