1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! # diffkit
//!
//! A library for diffing and patching sequences and nested structures.
//!
//! ## Features
//!
//! - **Myers diff** — efficient sequence diffing via the Myers algorithm
//! - **Recursive diff** — structural diffing of nested maps and sequences
//! - **Hunks** — group changes with context lines
//! - **Unified diff** — serialize and deserialize patches in unified diff format
//!
//! ## Quick Start
//!
//! A simple Vec of primitives can be diffed using Myers algorithm.
//! The diff can be transformed into a series of [`patch::Hunk`]s.
//! Hunks can be transformed into a textual diff or applied to an input.
//!
//! `apply(&old, hunks(diff(&old, &new))) == Ok(new)`
//!
//! ```rust
//! use diffkit::myers::diff;
//! use diffkit::patch::{apply, hunks};
//! use diffkit::serialization::ToPatch;
//!
//! let old = vec!["hello", "world"];
//! let new = vec!["hello", "rust"];
//! let myers_edits = diff(&old, &new);
//!
//! let hunks = hunks(myers_edits);
//! let patch = hunks.to_patch(Some("lib.rs"), Some("lib.rs"));
//!
//! let equal_to_new = apply(&old, &hunks);
//! ```
//!
//! For nested structures a recursive diffing algorithm is provided.
//! The diff will return a list of [`recursive::Change`]s.
//! Changes can be transformed into Hunks and applied.
//! Changes cannot be serialized, since there is no consensus on a textual format.
//!
//! `apply(&old, hunks(diff(&old, &new))) == Ok(new)`
//!
//! ```rust
//! use std::collections::HashMap;
//! use diffkit::recursive::{apply, diff};
//! use diffkit::patch::hunks;
//!
//! let mut old = HashMap::new();
//! old.insert("Hello".to_string(), 1);
//! let mut new = HashMap::new();
//! new.insert("Hello".to_string(), 2);
//! let changes = diff(&old, &new);
//!
//! let equal_to_new = apply(&old, &changes);
//! ```