struct_patch_trait/lib.rs
1/// Define the behavior between patch struct and original sturct
2pub mod traits {
3 /// The trait can apply patch and generete corresponding patch instance
4 pub trait Patch<P> {
5 /// Apply the patch, only update the existing fields
6 fn apply(&mut self, patch: P);
7
8 /// Diff on a previous state and into the patch instance
9 fn into_patch_by_diff(self, previous_struct: Self) -> P;
10
11 /// Get an empty patch instance
12 fn new_empty_patch() -> P;
13 }
14
15 #[cfg(feature = "status")]
16 /// The trait can check on the status of patch instance
17 pub trait PatchStatus {
18 /// There is any field need to patch
19 fn is_empty(&self) -> bool;
20 }
21}