pub trait DiffNode: Sized {
type Key: Eq + Hash;
type Modifications;
// Required methods
fn key(&self) -> &Self::Key;
fn path(&self) -> &[u32];
fn children(&self) -> &[Self];
fn compatible(&self, previous: &Self) -> bool;
fn modifications(&self, previous: &Self) -> Option<Self::Modifications>;
// Provided methods
fn diff(
&self,
previous: Option<&Self>,
diff: &mut Diff<Self::Modifications>,
) { ... }
fn validate_children(&self) { ... }
}Expand description
A tree node with stable sibling keys and index-based paths. Children must expose paths extending their parent’s path by their child index.
Required Associated Types§
Required Methods§
fn key(&self) -> &Self::Key
fn path(&self) -> &[u32]
fn children(&self) -> &[Self]
Sourcefn compatible(&self, previous: &Self) -> bool
fn compatible(&self, previous: &Self) -> bool
Whether these nodes have compatible kinds, independently of their keys.
Sourcefn modifications(&self, previous: &Self) -> Option<Self::Modifications>
fn modifications(&self, previous: &Self) -> Option<Self::Modifications>
Returns changes for compatible nodes with matching keys, or None if unchanged.
Provided Methods§
Sourcefn diff(&self, previous: Option<&Self>, diff: &mut Diff<Self::Modifications>)
fn diff(&self, previous: Option<&Self>, diff: &mut Diff<Self::Modifications>)
Appends changes from previous to self into diff.
Matching roots must have paths of equal depth and corresponding parents.
Examples found in repository?
examples/demo.rs (line 69)
56fn main() {
57 let previous = list(&[
58 ("apple", "Apple"),
59 ("banana", "Banana"),
60 ("cherry", "Cherry"),
61 ]);
62 let current = list(&[
63 ("banana", "Ripe banana"),
64 ("orange", "Orange"),
65 ("apple", "Apple"),
66 ]);
67
68 let mut changes = Diff::default();
69 current.diff(Some(&previous), &mut changes);
70
71 println!("Added at new paths: {:?}", changes.added);
72 println!("Removed at old paths: {:?}", changes.removed);
73 println!("New text at new paths: {:?}", changes.modified);
74 println!(
75 "Old/new child indices by new parent path: {:?}",
76 changes.moved
77 );
78}Sourcefn validate_children(&self)
fn validate_children(&self)
Checks application-specific sibling key rules before matching children in debug builds.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".