diff --git a/src/lib.rs b/src/lib.rs index ec4c145..7af53db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,13 +1,29 @@ //! This crate implements diffing utilities. It attempts to provide an abstraction //! interface over different types of diffing algorithms. It's based on the //! the diff algorithm implementations of [pijul](https://pijul.org/). + +//! ```rust +//! use similar::text::TextDiff; +//! # let old_text = ""; +//! # let new_text = ""; +//! let diff = TextDiff::from_chars("Hello World", "Hallo Welt"); +//! ``` //! -//! The crate is split into two modules: +//! ## Functionality //! //! * [`algorithms`]: This implements the different types of diffing algorithms. //! It provides both low level access to the algorithms with the minimal //! trait bounds necessary, as well as a generic interface. //! * [`text`]: This extends the general diffing functionality to text (and more //! specifically line) based diff operations. +//! +//! ## Optional Features +//! +//! The crate by default does not have any dependencies however for some use +//! cases it's useful to pull in extra functionality: +//! +//! * `unicode`: when this feature is enabled the text diffing functionality +//! gains the ability to diff on a grapheme instead of character level. This +//! is particularly useful when working with text containing emojis. pub mod algorithms; pub mod text; diff --git a/src/text.rs b/src/text.rs index 975ec0c..c1c149d 100644 --- a/src/text.rs +++ b/src/text.rs @@ -256,12 +256,12 @@ impl<'old, 'new, 'bufs> TextDiff<'old, 'new, 'bufs> { } /// Creates a diff of words. - pub fn from_words(&self, old: &'old str, new: &'new str) -> TextDiff<'old, 'new, 'bufs> { + pub fn from_words(old: &'old str, new: &'new str) -> TextDiff<'old, 'new, 'bufs> { Self::configure().diff_words(old, new) } /// Creates a diff of chars. - pub fn from_chars(&self, old: &'old str, new: &'new str) -> TextDiff<'old, 'new, 'bufs> { + pub fn from_chars(old: &'old str, new: &'new str) -> TextDiff<'old, 'new, 'bufs> { Self::configure().diff_chars(old, new) }