#diff

dissimilar

Diff library with semantic cleanup, based on Google's diff-match-patch

5 stable releases

1.0.4 Apr 29, 2022
1.0.3 Sep 26, 2021
1.0.2 Jun 16, 2020
1.0.1 Dec 24, 2019
1.0.0 Dec 23, 2019

#29 in Text processing

Download history 62283/week @ 2022-08-15 59503/week @ 2022-08-22 60494/week @ 2022-08-29 57653/week @ 2022-09-05 60498/week @ 2022-09-12 66813/week @ 2022-09-19 60951/week @ 2022-09-26 70303/week @ 2022-10-03 68143/week @ 2022-10-10 73902/week @ 2022-10-17 76670/week @ 2022-10-24 66939/week @ 2022-10-31 77478/week @ 2022-11-07 83393/week @ 2022-11-14 68459/week @ 2022-11-21 71406/week @ 2022-11-28

304,450 downloads per month
Used in 291 crates (18 directly)

Apache-2.0

71KB
1.5K SLoC

Dissimilar: diff library with semantic cleanup

github crates.io docs.rs build status

This library is a port of the Diff component of Diff Match Patch to Rust. The diff implementation is based on Myers' diff algorithm but includes some semantic cleanups to increase human readability by factoring out commonalities which are likely to be coincidental.

Diff Match Patch was originally built in 2006 to power Google Docs.

[dependencies]
dissimilar = "1.0"

Compiler support: requires rustc 1.31+


Interface

Here is the entire API of the Rust implementation. It operates on borrowed strings and the return value of the diff algorithm is a vector of chunks pointing into slices of those input strings.

pub enum Chunk<'a> {
    Equal(&'a str),
    Delete(&'a str),
    Insert(&'a str),
}

pub fn diff(text1: &str, text2: &str) -> Vec<Chunk>;

License

The diff algorithm in this crate was ported to Rust using the Java and C++ implementations found at https://github.com/google/diff-match-patch as reference, and is made available here under the Apache License, Version 2.0 matching the license of the original. This entire project, including some parts unmodified from upstream and the Rust-specific modifications introduced in the course of porting the implementation, are distributed under this Apache license.

Intellectual property that is unique to the Rust implementation is additionally made available to you dually under the MIT license, if you prefer. This applies to all design choices and implementation choices not found in the upstream repo.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual Apache and MIT licensed, without any additional terms or conditions.

No runtime deps