Crates.io | diffmatchpatch |
lib.rs | diffmatchpatch |
version | 0.0.4 |
source | src |
created_at | 2023-02-14 18:45:06.238901 |
updated_at | 2023-07-23 10:48:05.141346 |
description | Rewrite of diff-match-patch in Rust |
homepage | https://github.com/andelf/diffmatchpatch |
repository | https://github.com/andelf/diffmatchpatch |
max_upload_size | |
id | 785203 |
size | 223,749 |
The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronising plain text. This repository contains a Rust version of the original diff-match-patch library, using up-to-date crate packages.
Chars(Vec<char>)
to represent text instead of String
to avoid unnecessary traversing of the stringdiff_lines_to_chars
to diff_any_to_chars
to support words, lines, text blocks, and any sequence of comparable itemspatch
partprelude
modThe same example is copied from https://neil.fraser.name/software/diff_match_patch/demos/diff.html.
use diffmatchpatch::prelude::*;
fn main() {
let text1 = r#"I am the very model of a modern Major-General,
I've information vegetable, animal, and mineral,
I know the kings of England, and I quote the fights historical,
From Marathon to Waterloo, in order categorical."#;
let text2 = r#"I am the very model of a cartoon individual,
My animation's comical, unusual, and whimsical,
I'm quite adept at funny gags, comedic theory I have read,
From wicked puns and stupid jokes to anvils that drop on your head."#;
// No Cleanup
//let diffs = diff_main(text2, text1);
//println!("diffs {:#?}", diffs);
// Semantic Cleanup
let diffs = diff_semantic(text2, text1);
println!("Semantic diffs {:#?}", diffs);
// Word mode
let diffs = diff_word_mode(text2, text1);
println!("Word diffs {:#?}", diffs);
// diff_word_mode is also avaliable, but is meaningless to this example
}
This code is forked originally from dmp, licensed under the MIT license.
On an M1 Pro MacBook Pro:
Python3 8.695004s
JS(Chrome) 0.469s
speedtest 147.20 ms