Document grapheme diffing and fix from_chars/from_words

This commit is contained in:
Armin Ronacher 2021-01-24 09:13:15 +01:00
parent 1b96739cc3
commit 93ded2e62c
2 changed files with 19 additions and 3 deletions

View file

@ -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;

View file

@ -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)
}