diffkit 0.1.0

A library for diffing and patching sequences and nested structures
Documentation
  • Coverage
  • 44%
    22 out of 50 items documented5 out of 13 items with examples
  • Size
  • Source code size: 62.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 6.67 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • sphaso/diffkit
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • sphaso

diffkit

Build Status

A Rust 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

Installation

Add to your Cargo.toml:

[dependencies]
diffkit = "0.1.0"

Usage

Sequence diff

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

Recursive diff

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

Applying a patch

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

License

See UNLICENSE for details.