pub struct Diff { /* private fields */ }blob only.Expand description
Represents the difference between two sequences of tokens.
A Diff stores which tokens were removed from the first sequence and which tokens were added to the second sequence.
Implementations§
Source§impl Diff
impl Diff
Sourcepub fn postprocess_with(
&mut self,
before: &[Token],
after: &[Token],
heuristic: impl SliderHeuristic,
)
pub fn postprocess_with( &mut self, before: &[Token], after: &[Token], heuristic: impl SliderHeuristic, )
Postprocesses the diff using explicit token sequences and a custom heuristic.
This is a lower-level method that works directly with token sequences rather than
an InternedInput. Use postprocess_with_heuristic
for a more convenient API.
§Parameters
before- The token sequence from the first file, before changesafter- The token sequence from the second file, after changesheuristic- The slider heuristic to use for positioning hunks
Sourcepub fn postprocess_with_heuristic<T>(
&mut self,
input: &InternedInput<T>,
heuristic: impl SliderHeuristic,
)
pub fn postprocess_with_heuristic<T>( &mut self, input: &InternedInput<T>, heuristic: impl SliderHeuristic, )
Postprocesses the diff using an InternedInput and a custom heuristic.
This is a convenience wrapper around postprocess_with
that extracts the token sequences from the input automatically.
§Parameters
input- The interned input containing the token sequencesheuristic- The slider heuristic to use for positioning hunks
Source§impl Diff
impl Diff
Sourcepub fn compute<T>(algorithm: Algorithm, input: &InternedInput<T>) -> Diff
pub fn compute<T>(algorithm: Algorithm, input: &InternedInput<T>) -> Diff
Computes an edit-script that transforms input.before into input.after using
the specified algorithm
Sourcepub fn compute_with(
&mut self,
algorithm: Algorithm,
before: &[Token],
after: &[Token],
num_tokens: u32,
)
pub fn compute_with( &mut self, algorithm: Algorithm, before: &[Token], after: &[Token], num_tokens: u32, )
Computes an edit-script that transforms before into after using
the specified algorithm.
Sourcepub fn count_additions(&self) -> u32
pub fn count_additions(&self) -> u32
Returns the total number of tokens that were added in the second sequence.
Sourcepub fn count_removals(&self) -> u32
pub fn count_removals(&self) -> u32
Returns the total number of tokens that were removed from the first sequence (before).
Sourcepub fn is_removed(&self, token_idx: u32) -> bool
pub fn is_removed(&self, token_idx: u32) -> bool
Returns true if the token at the given index was removed from the first sequence (before).
§Panics
Panics if token_idx is out of bounds for the first sequence.
Sourcepub fn is_added(&self, token_idx: u32) -> bool
pub fn is_added(&self, token_idx: u32) -> bool
Returns true if the token at the given index was added to the second sequence (after).
§Panics
Panics if token_idx is out of bounds for the second sequence (after).
Sourcepub fn postprocess_no_heuristic<T>(&mut self, input: &InternedInput<T>)
pub fn postprocess_no_heuristic<T>(&mut self, input: &InternedInput<T>)
Postprocesses the diff to make it more human-readable. Certain hunks have an ambiguous placement (even in a minimal diff) where they can move downward or upward by removing a token (line) at the start and adding one at the end (or the other way around). The postprocessing adjusts these hunks according to a couple of rules:
- Always merge multiple hunks if possible.
- Always try to create a single MODIFY hunk instead of multiple disjoint ADDED/REMOVED hunks.
- Move sliders as far down as possible.
Sourcepub fn postprocess_lines<T>(&mut self, input: &InternedInput<T>)
pub fn postprocess_lines<T>(&mut self, input: &InternedInput<T>)
Postprocesses the diff to make it more human-readable. Certain hunks have an ambiguous placement (even in a minimal diff) where they can move downward or upward by removing a token (line) at the start and adding one at the end (or the other way around). The postprocessing adjusts these hunks according to a couple of rules:
- Always merge multiple hunks if possible.
- Always try to create a single MODIFY hunk instead of multiple disjoint ADDED/REMOVED hunks.
- Based on a line’s indentation level, heuristically compute the most intuitive location to split lines.
- Move sliders as far down as possible.