Struct similar::TextDiff

source ·
pub struct TextDiff<'old, 'new, 'bufs, T: DiffableStr + ?Sized> { /* private fields */ }
Expand description

Captures diff op codes for textual diffs.

The exact diff behavior is depending on the underlying DiffableStr. For instance diffs on bytes and strings are slightly different. You can create a text diff from constructors such as TextDiff::from_lines or the TextDiffConfig created by TextDiff::configure.

Requires the text feature.

Implementations

Configures a text differ before diffing.

Creates a diff of lines.

For more information see TextDiffConfig::diff_lines.

Creates a diff of words.

For more information see TextDiffConfig::diff_words.

Creates a diff of chars.

For more information see TextDiffConfig::diff_chars.

Creates a diff of unicode words.

For more information see TextDiffConfig::diff_unicode_words.

This requires the unicode feature.

Creates a diff of graphemes.

For more information see TextDiffConfig::diff_graphemes.

This requires the unicode feature.

Creates a diff of arbitrary slices.

For more information see TextDiffConfig::diff_slices.

The name of the algorithm that created the diff.

Returns true if items in the slice are newline terminated.

This flag is used by the unified diff writer to determine if extra newlines have to be added.

Returns all old slices.

Returns all new slices.

Return a measure of the sequences’ similarity in the range 0..=1.

A ratio of 1.0 means the two sequences are a complete match, a ratio of 0.0 would indicate completely distinct sequences.

let diff = TextDiff::from_chars("abcd", "bcde");
assert_eq!(diff.ratio(), 0.75);

Iterates over the changes the op expands to.

This method is a convenient way to automatically resolve the different ways in which a change could be encoded (insert/delete vs replace), look up the value from the appropriate slice and also handle correct index handling.

Returns the captured diff ops.

Isolate change clusters by eliminating ranges with no changes.

This is equivalent to calling group_diff_ops on TextDiff::ops.

Flattens out the diff into all changes.

This is a shortcut for combining TextDiff::ops with TextDiff::iter_changes.

Utility to return a unified diff formatter.

Iterates over the changes the op expands to with inline emphasis.

This is very similar to TextDiff::iter_changes but it performs a second level diff on adjacent line replacements. The exact behavior of this function with regards to how it detects those inline changes is currently not defined and will likely change over time.

As of similar 1.2.0 the behavior of this function changes depending on if the unicode feature is enabled or not. It will prefer unicode word splitting over word splitting depending on the feature flag.

Requires the inline feature.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.