#diff-match-patch #diff #algorithm #semantic #cleanup #myers #google

dissimilar

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

10 stable releases

1.0.9 May 6, 2024
1.0.7 Jul 15, 2023
1.0.6 Jan 20, 2023
1.0.5 Dec 17, 2022
1.0.1 Dec 24, 2019

#14 in Algorithms

Download history 132699/week @ 2024-08-15 147562/week @ 2024-08-22 146901/week @ 2024-08-29 167704/week @ 2024-09-05 146667/week @ 2024-09-12 153926/week @ 2024-09-19 158207/week @ 2024-09-26 144961/week @ 2024-10-03 156499/week @ 2024-10-10 176246/week @ 2024-10-17 151361/week @ 2024-10-24 159139/week @ 2024-10-31 147789/week @ 2024-11-07 182133/week @ 2024-11-14 161224/week @ 2024-11-21 122317/week @ 2024-11-28

640,601 downloads per month
Used in 644 crates (40 directly)

Apache-2.0

70KB
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.36+


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