Struct similar::TextDiff [−][src]
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
impl<'old, 'new, 'bufs> TextDiff<'old, 'new, 'bufs, str>
[src]
pub fn configure() -> TextDiffConfig
[src]
Configures a text differ before diffing.
pub fn from_lines<T: DiffableStrRef + ?Sized>(
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of lines.
For more information see TextDiffConfig::diff_lines
.
pub fn from_words<T: DiffableStrRef + ?Sized>(
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of words.
For more information see TextDiffConfig::diff_words
.
pub fn from_chars<T: DiffableStrRef + ?Sized>(
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of chars.
For more information see TextDiffConfig::diff_chars
.
pub fn from_unicode_words<T: DiffableStrRef + ?Sized>(
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of unicode words.
For more information see TextDiffConfig::diff_unicode_words
.
This requires the unicode
feature.
pub fn from_graphemes<T: DiffableStrRef + ?Sized>(
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of graphemes.
For more information see TextDiffConfig::diff_graphemes
.
This requires the unicode
feature.
impl<'old, 'new, 'bufs, T: DiffableStr + ?Sized + 'old + 'new> TextDiff<'old, 'new, 'bufs, T>
[src]
pub fn from_slices(
old: &'bufs [&'old T],
new: &'bufs [&'new T]
) -> TextDiff<'old, 'new, 'bufs, T>
[src]
old: &'bufs [&'old T],
new: &'bufs [&'new T]
) -> TextDiff<'old, 'new, 'bufs, T>
Creates a diff of arbitrary slices.
For more information see TextDiffConfig::diff_slices
.
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 T]
[src]
Returns all old slices.
pub fn new_slices(&self) -> &[&'new T]
[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<'x, 'slf>(
&'slf self,
op: &DiffOp
) -> ChangesIter<'slf, 'x, [&'x T], [&'x T], T>ⓘNotable traits for ChangesIter<'lookup, 'data, Old, New, T>
impl<'lookup, 'data, Old: ?Sized, New: ?Sized, T: ?Sized> Iterator for ChangesIter<'lookup, 'data, Old, New, T> where
Old: Index<usize, Output = &'data T>,
New: Index<usize, Output = &'data T>,
T: 'data,
'data: 'lookup, type Item = Change<'data, T>;
where
'x: 'slf,
'old: 'x,
'new: 'x,
[src]
&'slf self,
op: &DiffOp
) -> ChangesIter<'slf, 'x, [&'x T], [&'x T], T>ⓘ
Notable traits for ChangesIter<'lookup, 'data, Old, New, T>
impl<'lookup, 'data, Old: ?Sized, New: ?Sized, T: ?Sized> Iterator for ChangesIter<'lookup, 'data, Old, New, T> where
Old: Index<usize, Output = &'data T>,
New: Index<usize, Output = &'data T>,
T: 'data,
'data: 'lookup, type Item = Change<'data, T>;
'x: 'slf,
'old: 'x,
'new: 'x,
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.
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 iter_all_changes<'x, 'slf>(&'slf self) -> AllChangesIter<'slf, 'x, T>ⓘNotable traits for AllChangesIter<'slf, 'data, T>
impl<'slf, 'data, T: ?Sized> Iterator for AllChangesIter<'slf, 'data, T> where
T: PartialEq + 'data,
'data: 'slf, type Item = Change<'data, T>;
where
'x: 'slf + 'old + 'new,
'old: 'x,
'new: 'x,
[src]
Notable traits for AllChangesIter<'slf, 'data, T>
impl<'slf, 'data, T: ?Sized> Iterator for AllChangesIter<'slf, 'data, T> where
T: PartialEq + 'data,
'data: 'slf, type Item = Change<'data, T>;
'x: 'slf + 'old + 'new,
'old: 'x,
'new: 'x,
Flattens out the diff into all changes.
This is a shortcut for combining TextDiff::ops
with
TextDiff::iter_changes
.
pub fn unified_diff<'diff>(
&'diff self
) -> UnifiedDiff<'diff, 'old, 'new, 'bufs, T>
[src]
&'diff self
) -> UnifiedDiff<'diff, 'old, 'new, 'bufs, T>
Utility to return a unified diff formatter.
pub fn iter_inline_changes<'slf>(
&'slf self,
op: &DiffOp
) -> impl Iterator<Item = InlineChange<'slf, T>> + '_ where
'slf: 'old + 'new,
[src]
&'slf self,
op: &DiffOp
) -> impl Iterator<Item = InlineChange<'slf, T>> + '_ where
'slf: 'old + 'new,
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
impl<'old, 'new, 'bufs, T: ?Sized> RefUnwindSafe for TextDiff<'old, 'new, 'bufs, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<'old, 'new, 'bufs, T: ?Sized> Send for TextDiff<'old, 'new, 'bufs, T> where
T: Sync,
T: Sync,
impl<'old, 'new, 'bufs, T: ?Sized> Sync for TextDiff<'old, 'new, 'bufs, T> where
T: Sync,
T: Sync,
impl<'old, 'new, 'bufs, T: ?Sized> Unpin for TextDiff<'old, 'new, 'bufs, T> where
'new: 'bufs,
'old: 'bufs,
'new: 'bufs,
'old: 'bufs,
impl<'old, 'new, 'bufs, T: ?Sized> UnwindSafe for TextDiff<'old, 'new, 'bufs, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,