Struct similar::TextDiffConfig [−][src]
A builder type config for more complex uses of TextDiff
.
Requires the text
feature.
Implementations
impl TextDiffConfig
[src]
pub fn algorithm(&mut self, alg: Algorithm) -> &mut Self
[src]
Changes the algorithm.
The default algorithm is Algorithm::Myers
.
pub fn deadline(&mut self, deadline: Instant) -> &mut Self
[src]
Sets a deadline for the diff operation.
By default a diff will take as long as it takes. For certain diff algorthms like Myer’s and Patience a maximum running time can be defined after which the algorithm gives up and approximates.
pub fn timeout(&mut self, timeout: Duration) -> &mut Self
[src]
Sets a timeout for thediff operation.
This is like deadline
but accepts a duration.
pub fn newline_terminated(&mut self, yes: bool) -> &mut Self
[src]
Changes the newline termination flag.
The default is automatic based on input. This flag controls the
behavior of TextDiff::iter_changes
and unified diff generation
with regards to newlines. When the flag is set to false
(which
is the default) then newlines are added. Otherwise the newlines
from the source sequences are reused.
pub fn diff_lines<'old, 'new, 'bufs, T: DiffableStrRef + ?Sized>(
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of lines.
This splits the text old
and new
into lines preserving newlines
in the input. Line diffs are very common and because of that enjoy
special handling in similar. When a line diff is created with this
method the newline_terminated
flag is flipped to true
and will
influence the behavior of unified diff generation.
use similar::{TextDiff, ChangeTag}; let diff = TextDiff::configure().diff_lines("a\nb\nc", "a\nb\nC"); let changes: Vec<_> = diff .iter_all_changes() .map(|x| (x.tag(), x.value())) .collect(); assert_eq!(changes, vec![ (ChangeTag::Equal, "a\n"), (ChangeTag::Equal, "b\n"), (ChangeTag::Delete, "c"), (ChangeTag::Insert, "C"), ]);
pub fn diff_words<'old, 'new, 'bufs, T: DiffableStrRef + ?Sized>(
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of words.
This splits the text into words and whitespace.
Note on word diffs: because the text differ will tokenize the strings
into small segments it can be inconvenient to work with the results
depending on the use case. You might also want to combine word level
diffs with the TextDiffRemapper
which lets you remap the diffs back to the original input strings.
use similar::{TextDiff, ChangeTag}; let diff = TextDiff::configure().diff_words("foo bar baz", "foo BAR baz"); let changes: Vec<_> = diff .iter_all_changes() .map(|x| (x.tag(), x.value())) .collect(); assert_eq!(changes, vec![ (ChangeTag::Equal, "foo"), (ChangeTag::Equal, " "), (ChangeTag::Delete, "bar"), (ChangeTag::Insert, "BAR"), (ChangeTag::Equal, " "), (ChangeTag::Equal, "baz"), ]);
pub fn diff_chars<'old, 'new, 'bufs, T: DiffableStrRef + ?Sized>(
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of characters.
Note on character diffs: because the text differ will tokenize the strings
into small segments it can be inconvenient to work with the results
depending on the use case. You might also want to combine word level
diffs with the TextDiffRemapper
which lets you remap the diffs back to the original input strings.
use similar::{TextDiff, ChangeTag}; let diff = TextDiff::configure().diff_chars("abcdef", "abcDDf"); let changes: Vec<_> = diff .iter_all_changes() .map(|x| (x.tag(), x.value())) .collect(); assert_eq!(changes, vec![ (ChangeTag::Equal, "a"), (ChangeTag::Equal, "b"), (ChangeTag::Equal, "c"), (ChangeTag::Delete, "d"), (ChangeTag::Delete, "e"), (ChangeTag::Insert, "D"), (ChangeTag::Insert, "D"), (ChangeTag::Equal, "f"), ]);
pub fn diff_unicode_words<'old, 'new, 'bufs, T: DiffableStrRef + ?Sized>(
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of unicode words.
This splits the text into words according to unicode rules. This is
generally recommended over TextDiffConfig::diff_words
but
requires a dependency.
This requires the unicode
feature.
Note on word diffs: because the text differ will tokenize the strings
into small segments it can be inconvenient to work with the results
depending on the use case. You might also want to combine word level
diffs with the TextDiffRemapper
which lets you remap the diffs back to the original input strings.
use similar::{TextDiff, ChangeTag}; let diff = TextDiff::configure().diff_unicode_words("ah(be)ce", "ah(ah)ce"); let changes: Vec<_> = diff .iter_all_changes() .map(|x| (x.tag(), x.value())) .collect(); assert_eq!(changes, vec![ (ChangeTag::Equal, "ah"), (ChangeTag::Equal, "("), (ChangeTag::Delete, "be"), (ChangeTag::Insert, "ah"), (ChangeTag::Equal, ")"), (ChangeTag::Equal, "ce"), ]);
pub fn diff_graphemes<'old, 'new, 'bufs, T: DiffableStrRef + ?Sized>(
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
[src]
&self,
old: &'old T,
new: &'new T
) -> TextDiff<'old, 'new, 'bufs, T::Output>
Creates a diff of graphemes.
This requires the unicode
feature.
Note on grapheme diffs: because the text differ will tokenize the strings
into small segments it can be inconvenient to work with the results
depending on the use case. You might also want to combine word level
diffs with the TextDiffRemapper
which lets you remap the diffs back to the original input strings.
use similar::{TextDiff, ChangeTag}; let diff = TextDiff::configure().diff_graphemes("💩🇦🇹🦠", "💩🇦🇱❄️"); let changes: Vec<_> = diff .iter_all_changes() .map(|x| (x.tag(), x.value())) .collect(); assert_eq!(changes, vec![ (ChangeTag::Equal, "💩"), (ChangeTag::Delete, "🇦🇹"), (ChangeTag::Delete, "🦠"), (ChangeTag::Insert, "🇦🇱"), (ChangeTag::Insert, "❄️"), ]);
pub fn diff_slices<'old, 'new, 'bufs, T: DiffableStr + ?Sized>(
&self,
old: &'bufs [&'old T],
new: &'bufs [&'new T]
) -> TextDiff<'old, 'new, 'bufs, T>
[src]
&self,
old: &'bufs [&'old T],
new: &'bufs [&'new T]
) -> TextDiff<'old, 'new, 'bufs, T>
Creates a diff of arbitrary slices.
use similar::{TextDiff, ChangeTag}; let old = &["foo", "bar", "baz"]; let new = &["foo", "BAR", "baz"]; let diff = TextDiff::configure().diff_slices(old, new); let changes: Vec<_> = diff .iter_all_changes() .map(|x| (x.tag(), x.value())) .collect(); assert_eq!(changes, vec![ (ChangeTag::Equal, "foo"), (ChangeTag::Delete, "bar"), (ChangeTag::Insert, "BAR"), (ChangeTag::Equal, "baz"), ]);
Trait Implementations
impl Clone for TextDiffConfig
[src]
fn clone(&self) -> TextDiffConfig
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for TextDiffConfig
[src]
impl Default for TextDiffConfig
[src]
fn default() -> TextDiffConfig
[src]
Auto Trait Implementations
impl RefUnwindSafe for TextDiffConfig
impl Send for TextDiffConfig
impl Sync for TextDiffConfig
impl Unpin for TextDiffConfig
impl UnwindSafe for TextDiffConfig
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> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
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>,