Struct similar::text::TextDiff[][src]

pub struct TextDiff<'old, 'new, 'bufs> { /* fields omitted */ }

Captures diff op codes for textual diffs

Implementations

impl<'old, 'new, 'bufs> TextDiff<'old, 'new, 'bufs>[src]

pub fn configure() -> TextDiffConfig[src]

Configures a text differ before diffing.

pub fn from_lines(old: &'old str, new: &'new str) -> TextDiff<'old, 'new, 'bufs>[src]

Creates a diff of lines.

Equivalent to TextDiff::configure().diff_lines(old, new).

pub fn from_words(old: &'old str, new: &'new str) -> TextDiff<'old, 'new, 'bufs>[src]

Creates a diff of words.

Equivalent to TextDiff::configure().diff_words(old, new).

pub fn from_chars(old: &'old str, new: &'new str) -> TextDiff<'old, 'new, 'bufs>[src]

Creates a diff of chars.

Equivalent to TextDiff::configure().diff_chars(old, new).

pub fn from_graphemes(
    old: &'old str,
    new: &'new str
) -> TextDiff<'old, 'new, 'bufs>
[src]

Creates a diff of graphemes.

Equivalent to TextDiff::configure().diff_graphemes(old, new).

This requires the unicode feature.

pub fn from_slices(
    old: &'bufs [&'old str],
    new: &'bufs [&'new str]
) -> TextDiff<'old, 'new, 'bufs>
[src]

Creates a diff of arbitrary slices.

Equivalent to TextDiff::configure().diff_slices(old, new).

pub fn algorithm(&self) -> Algorithm[src]

The name of the algorithm that created the diff.

pub fn newline_terminated(&self) -> bool[src]

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.

pub fn old_slices(&self) -> &[&'old str][src]

Returns all old slices.

pub fn new_slices(&self) -> &[&'new str][src]

Returns all new slices.

pub fn ratio(&self) -> f32[src]

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);

pub fn iter_changes(&self, op: &DiffOp) -> impl Iterator<Item = Change<'_>>[src]

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.

In addition it has some custom handling to insert "virtual" newlines for diffs where TextDiff::newline_terminated is true but the diff does not end in newlines in the right places. For more information see Change::is_virtual.

pub fn ops(&self) -> &[DiffOp][src]

Returns the captured diff ops.

pub fn grouped_ops(&self, n: usize) -> Vec<Vec<DiffOp>>[src]

Isolate change clusters by eliminating ranges with no changes.

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

pub fn unified_diff<'diff>(&'diff self) -> UnifiedDiff<'diff, 'old, 'new, 'bufs>[src]

Utility to return a unified diff formatter.

Auto Trait Implementations

impl<'old, 'new, 'bufs> RefUnwindSafe for TextDiff<'old, 'new, 'bufs>[src]

impl<'old, 'new, 'bufs> Send for TextDiff<'old, 'new, 'bufs>[src]

impl<'old, 'new, 'bufs> Sync for TextDiff<'old, 'new, 'bufs>[src]

impl<'old, 'new, 'bufs> Unpin for TextDiff<'old, 'new, 'bufs> where
    'new: 'bufs,
    'old: 'bufs, 
[src]

impl<'old, 'new, 'bufs> UnwindSafe for TextDiff<'old, 'new, 'bufs>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.