pub trait Sink: Sized {
type Out;
// Required methods
fn process_change(&mut self, before: Range<u32>, after: Range<u32>);
fn finish(self) -> Self::Out;
// Provided method
fn with_counter(self) -> Counter<Self> { ... }
}
blob
only.Expand description
Trait for processing the edit-scripts computed with diff
Required Associated Types§
Required Methods§
sourcefn process_change(&mut self, before: Range<u32>, after: Range<u32>)
fn process_change(&mut self, before: Range<u32>, after: Range<u32>)
This method is called whenever a diff algorithm
finds a change between the two processed input file.
A change is a continous subsequence of tokens before
that needs
to be replaced by a different contious subsequence of tokens after
to construct the seconds file from the first.
These token subsequences are passed to this function in in ** strictly montonically increasing order**.
That means that for two subsequenct calls process_change(before1, after1)
and process_change(before2, after2)
the following always holds:
assert!(before1.end < before2.start);
assert!(after1.end < after2.start);
Paramters
before
- the position of the removed token subsequence in the orignal file.after
- the position of the inserted token subsequence in the destination file.
Notes
A Sink
has no function to indicate that a section of a file remains unchanged.
However due to the montonically increasing calls, implementations can easily determine
which subsequences remain unchanged by saving before.end
/after.end
.
The range between before.start
/after.end
and the previous before.end
/after.end
is always unchanged.
Provided Methods§
sourcefn with_counter(self) -> Counter<Self>
fn with_counter(self) -> Counter<Self>
Utility method that constructs a Counter
that tracks the total number
of inserted and removed tokens in the changes passed to process_change
.