From b088bdd9dc7ef838aa06e5100fe3bda739b255ff Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 30 Jan 2021 23:19:59 +0100 Subject: [PATCH] Updated readme --- README.md | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 42bd5d5..4c2f508 100644 --- a/README.md +++ b/README.md @@ -14,19 +14,34 @@ It's intended to be replacement for the popular but unmaintained [difference] crate. ```rust -use similar::algorithms::Algorithm; -use similar::text::unified_diff; +use similar::text::{ChangeTag, TextDiff}; -let udiff = unified_diff( - Algorithm::Patience, - old_text, - new_text, - 3, - Some(("old.txt", "new.text")) -); -println!("{}", udiff); +fn main() { + let diff = TextDiff::from_lines( + "Hello World\nThis is the second line.\nThis is the third.", + "Hallo Welt\nThis is the second line.\nThis is life.\nMoar and more", + ); + + for op in diff.ops() { + for change in diff.iter_changes(op) { + let sign = match change.tag() { + ChangeTag::Delete => "-", + ChangeTag::Insert => "+", + ChangeTag::Equal => " ", + }; + print!("{}{}", sign, change); + } + } +} ``` +## What's in the box? + +* Myer's diff +* Patience diff +* Line, word, character and grapheme level diffing +* Unified diff generation + ## License and Links - [Documentation](https://docs.rs/similar/)