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