Skip to main content

DiffUtils

Struct DiffUtils 

Source
pub struct DiffUtils;

Implementations§

Source§

impl DiffUtils

Source

pub fn with_default_diff_algorithm_factory( factory: Box<dyn DiffAlgorithmFactory<String> + Send + Sync>, )

Source

pub fn diff<T>( original: &[T], revised: &[T], progress: Option<&dyn DiffAlgorithmListener>, ) -> Patch<T>
where T: PartialEq + Clone + 'static,

Computes the diff between original and revised using the default algorithm.

§Algorithm

The default algorithm is HistogramDiff. It uses low-occurrence element anchors to split the sequence recursively, and falls back to Myers’ linear-space algorithm for high-entropy regions.

§Performance

Histogram is generally faster than Myers for files with repeated structure (e.g. source code), but Myers can be faster for high-entropy inputs where all elements are unique. For workloads where you know the input is high-entropy, call diff_with_algorithm and pass a MyersDiff instance explicitly.

Source

pub fn diff_with_options<T>( original: &[T], revised: &[T], include_equal_parts: bool, ) -> Patch<T>
where T: PartialEq + Clone + 'static,

Source

pub fn diff_text( source_text: &str, target_text: &str, progress: Option<&dyn DiffAlgorithmListener>, ) -> Patch<String>

Source

pub fn diff_with_equalizer<T, F>( source: &[T], target: &[T], equalizer: Option<F>, ) -> Patch<T>
where T: PartialEq + Clone + 'static, F: Fn(&T, &T) -> bool + Send + Sync + 'static,

Computes the diff with an optional custom element equality predicate.

§Note

When equalizer is Some, this method uses MyersDiff rather than the HistogramDiff default, because HistogramDiff’s custom-equalizer path requires T: 'static which is not always available. If you need HistogramDiff with a custom equalizer, construct one directly:

let algo = HistogramDiff::new().with_equalizer(|a, b| a.eq_ignore_ascii_case(b));
DiffUtils::diff_with_algorithm(&source, &target, &algo, None, false);
Source

pub fn diff_with_algorithm<T>( original: &[T], revised: &[T], algorithm: &dyn DiffAlgorithm<T>, _progress: Option<&dyn DiffAlgorithmListener>, include_equal_parts: bool, ) -> Patch<T>
where T: Clone + 'static,

Source

pub fn diff_inline(original: &str, revised: &str) -> Patch<String>

Source

pub fn patch<T>( original: &[T], patch: &Patch<T>, ) -> Result<Vec<T>, PatchFailedException>
where T: PartialEq + Clone,

Source

pub fn unpatch<T>( revised: &[T], patch: &Patch<T>, ) -> Result<Vec<T>, PatchFailedException>
where T: PartialEq + Clone,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.