Hi! I am using two libraries for my project: serde and diff-struct
diff-struct allows me to generate a diff between two structs of the same type. It comes with a trait Diff that lets me write code like this:
use diff::Diff;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Diff, PartialEq, Debug)]
struct Entity {
x: i32,
y: i32
}
fn main() {
let mut entity = Entity { x: 1, y: 1 };
let entity2 = Entity { x: 1, y: 2 };
let diff: EntityDiff = entity.diff(&entity2);
entity.apply(&diff);
assert_eq!(entity, entity2);
}
entity_diff in this code is of type EntityDiff, which is an associated type for the trait Diff.
Now here comes the problem: since I derive Diff I am not defining this associated type. This is an issue because I want to derive Serialize and Deserialize on this associated type.
Is there a way to do this?
Sorry if my explanation isn't quite clear. I'm still a bit new to rust and especially associated types and derives.