gix_diff::blob::sink

Trait Sink

Source
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> { ... }
}
Available on crate feature blob only.
Expand description

Trait for processing the edit-scripts computed with diff

Required Associated Types§

Required Methods§

Source

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.

Source

fn finish(self) -> Self::Out

This function is called after all calls to process_change are complete to obtain the final diff result

Provided Methods§

Source

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Sink for ()

Source§

type Out = ()

Source§

fn process_change(&mut self, _before: Range<u32>, _after: Range<u32>)

Source§

fn finish(self) -> <() as Sink>::Out

Implementors§

Source§

impl<S> Sink for Counter<S>
where S: Sink,

Source§

type Out = Counter<<S as Sink>::Out>

Source§

impl<T> Sink for T
where T: FnMut(Range<u32>, Range<u32>),

Source§

impl<W, T> Sink for UnifiedDiffBuilder<'_, W, T>
where W: Write, T: Hash + Eq + Display,

Source§

type Out = W