From d0a715d7af06ee57d5a030cd3007ffc220af0493 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 30 Jan 2021 23:23:11 +0100 Subject: [PATCH] Fixed example in readme and update lib.rs example --- README.md | 2 +- src/lib.rs | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4c2f508..1656312 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ fn main() { ChangeTag::Insert => "+", ChangeTag::Equal => " ", }; - print!("{}{}", sign, change); + print!("{}{}", sign, change.value()); } } } diff --git a/src/lib.rs b/src/lib.rs index 1c33e6c..09ddb3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,10 +4,23 @@ //! //! ```rust //! # #[cfg(feature = "text")] { -//! use similar::text::TextDiff; -//! # let old_text = ""; -//! # let new_text = ""; -//! let diff = TextDiff::from_chars("Hello World", "Hallo Welt"); +//! use similar::text::{ChangeTag, TextDiff}; +//! +//! 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.value()); +//! } +//! } //! # } //! ``` //!