Skip to content

Commit 136741e

Browse files
daladimJérôme Froissart
authored andcommitted
[doc] Added references to 3-way merging of arbitrary data
1 parent 6321dce commit 136741e

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

src/lib.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
//! Tools for finding and manipulating differences between files
22
//!
3-
//! ## Overview
3+
//! # Overview
44
//!
55
//! This library is intended to be a collection of tools used to find and
6-
//! manipulate differences between files inspired by [LibXDiff] and [GNU
7-
//! Diffutils]. Version control systems like [Git] and [Mercurial] generally
8-
//! communicate differences between two versions of a file using a `diff` or
9-
//! `patch`.
6+
//! manipulate differences between files or arbitrary data inspired by
7+
//! [LibXDiff] and [GNU Diffutils]. Version control systems like [Git] and
8+
//! [Mercurial] generallycommunicate differences between two versions of a
9+
//! file using a `diff` or `patch`.
1010
//!
1111
//! The current diff implementation is based on the [Myers' diff algorithm].
1212
//!
13+
//! ## Supported features
14+
//!
15+
//! | Feature | UTF-8 strings | non-UTF-8 string | Arbitrary types (that implement `Eq + Hash`) |
16+
//! |------------------|---------------|------------------|----------------------------------------------|
17+
//! | Creating a patch | ✅ | ✅ | |
18+
//! | Applying a patch | ✅ | ✅ | |
19+
//! | 3-way merge | ✅ | ✅ | ✅ |
20+
//!
21+
//! "Arbitrary types" means "any type that implements `Eq + Hash`".<br/>
22+
//! Supporting patches for arbitrary types would not be very helpful, since
23+
//! there is no standardized way of formatting them.
24+
//!
1325
//! ## UTF-8 and Non-UTF-8
1426
//!
1527
//! This library has support for working with both utf8 and non-utf8 texts.
@@ -198,6 +210,22 @@
198210
//! assert_eq!(merge(original, a, b).unwrap_err(), expected);
199211
//! ```
200212
//!
213+
//! It is possible to perform 3-way merges between collections of arbitrary
214+
//! types `T` as long as `T: Eq + Hash`.
215+
//! ```
216+
//! use diffy::merge_custom;
217+
//!
218+
//! let original = [1,2,3,4,5, 6];
219+
//! let a = [1,2,3,4,5,100,6];
220+
//! let b = [1, 3,4,5, 6];
221+
//! let expected = [1, 3,4,5,100,6];
222+
//!
223+
//! let result = merge_custom(&original, &a, &b).unwrap();
224+
//! let result_owned: Vec<i32> = result.iter().map(|r| **r).collect();
225+
//! assert_eq!(result_owned, expected);
226+
//! ```
227+
//!
228+
//!
201229
//! [LibXDiff]: http://www.xmailserver.org/xdiff-lib.html
202230
//! [Myers' diff algorithm]: http://www.xmailserver.org/diff2.pdf
203231
//! [GNU Diffutils]: https://www.gnu.org/software/diffutils/

0 commit comments

Comments
 (0)