Expand description
Structural diff and patch via datatype-generic representation.
Works with any type implementing GenericRepr by computing diffs on
the Sum/Product/Unit encoding and applying patches to transform values.
§Example
use ftui_core::generic_repr::*;
use ftui_core::generic_diff::*;
#[derive(Clone, Debug, PartialEq)]
struct Point { x: f64, y: f64 }
impl GenericRepr for Point {
type Repr = Product<f64, Product<f64, Unit>>;
fn into_repr(self) -> Self::Repr {
Product(self.x, Product(self.y, Unit))
}
fn from_repr(repr: Self::Repr) -> Self {
Point { x: repr.0, y: repr.1.0 }
}
}
let old = Point { x: 1.0, y: 2.0 };
let new = Point { x: 1.0, y: 3.0 };
let diff = generic_diff(&old, &new);
let patched = generic_patch(&old, &diff);
assert_eq!(patched, new);
assert!(!diff.is_empty());Structs§
- Product
Diff - Diff of a product: diff each component independently.
- Unit
Diff - Diff of a Unit: always empty (nothing to compare).
Enums§
- Delta
- A change delta: either unchanged or replaced with a new value.
- SumDiff
- Diff of a sum type: either both are the same variant (structural diff) or the variant changed (full replacement).
- Void
Diff - Void has no values, so Diff is trivially never called. We need the impl for sum chains to terminate.
Traits§
- Diff
- Compute a structural diff between two values of the same type.
- Diff
Info - Metadata about a diff.
- Leaf
Diff - Marker trait for types that use leaf-level (PartialEq) diffing.
- Patch
- Apply a diff to transform a value.
Functions§
- generic_
diff - Compute a structural diff between two values via their generic representation.
- generic_
patch - Apply a structural diff to transform a value via its generic representation.