Crates.io | slice-diff-patch |
lib.rs | slice-diff-patch |
version | 1.2.1 |
source | src |
created_at | 2022-02-05 18:01:43.490975 |
updated_at | 2022-02-11 19:30:04.957877 |
description | Library crate providing utility functions for diff and patch of slices |
homepage | https://github.com/qtfkwk/slice-diff-patch |
repository | https://github.com/qtfkwk/slice-diff-patch |
max_upload_size | |
id | 527520 |
size | 20,243 |
This crate provides the Change
enum as an abstraction for diff::Result
,
lcs_diff::DiffResult
, and wu_diff::DiffResult
; the diff_changes()
, diff_diff()
,
lcs_changes()
, lcs_diff()
, wu_changes()
, and wu_diff()
functions to calculate or
process diffs between a
and b
slices via LCS (Longest Common Subsequence) or Wu diff algorithms
into a Vec<Change>
, the patch()
function to reproduce b
from the a
slice and
Vec<Change>
, and the insert()
and remove()
functions to enable writing a custom
changes
function.
use slice_diff_patch::*;
let a = vec!["one", "TWO", "three", "four"];
let b = vec!["zero", "one", "two", "four"];
let diff = diff_diff(&a, &b);
assert_eq!(
diff,
vec![
Change::Insert((0, "zero")),
Change::Remove(2),
Change::Update((2, "two")),
],
);
assert_eq!(patch(&a, &diff), b);
let lcs = lcs_diff(&a, &b);
assert_eq!(
lcs,
vec![
Change::Insert((0, "zero")),
Change::Update((2, "two")),
Change::Remove(3),
],
);
assert_eq!(patch(&a, &lcs), b);
let wu = wu_diff(&a, &b);
assert_eq!(
wu,
vec![
Change::Insert((0, "zero")),
Change::Remove(2),
Change::Update((2, "two")),
],
);
assert_eq!(patch(&a, &wu), b);
See also:
Changelog:
Clone
on Change
Update
variant on Change
remove()
and insert()
functions