#diff

dissimilar

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

4 stable releases

1.0.3 Sep 26, 2021
1.0.2 Jun 16, 2020
1.0.1 Dec 24, 2019
1.0.0 Dec 23, 2019

#53 in Algorithms

Download history 20090/week @ 2021-08-10 22462/week @ 2021-08-17 25351/week @ 2021-08-24 25651/week @ 2021-08-31 28026/week @ 2021-09-07 28211/week @ 2021-09-14 27987/week @ 2021-09-21 30036/week @ 2021-09-28 31581/week @ 2021-10-05 30605/week @ 2021-10-12 30997/week @ 2021-10-19 28802/week @ 2021-10-26 29964/week @ 2021-11-02 32925/week @ 2021-11-09 32950/week @ 2021-11-16 29042/week @ 2021-11-23

129,826 downloads per month
Used in 151 crates (14 directly)

MIT/Apache

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.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

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
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 licensed as above, without any additional terms or conditions.

No runtime deps