Rust library crate providing utility functions for diff and patch of slices

Overview

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:

  • 0.1.0: initial
  • 0.2.0: add support for diff crate
  • 0.2.1: fix readme
  • 0.2.2: fix readme
  • 0.3.0: derive Clone on Change
  • 1.0.0: add Update variant on Change
  • 1.1.0: add doc test example
  • 1.1.1: fix readme
  • 1.2.1: expose remove() and insert() functions
You might also like...
Pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way.

DNG-rs   A pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way. Also containing code for re

A library providing helpers for various StarkNet fees related tasks.
A library providing helpers for various StarkNet fees related tasks.

🐺 How Much ? 🦀 Table of Contents About Getting Started Prerequisites Installation Usage Estimate fees on network Authors & contributors Security Lic

Specification for a decomp settings file & library for providing settings to tools

Decomp Settings File There are a lot of decompilation tools. Common metadata like the location of the .map file and target file are often needed by th

This crate provides a set of functions to generate SQL statements for various PostgreSQL schema objects

This crate provides a set of functions to generate SQL statements for various PostgreSQL schema objects, such as tables, views, materialized views, functions, triggers, and indexes. The generated SQL statements can be useful for schema introspection, documentation, or migration purposes.

Are we lang yet? A simple website providing information about the status of Rust's language development ecosystem.

Are We Lang Yet This project answers the question "Is the Rust ecosystem ready to use for language development yet?". arewelangyet.com What is this? C

Shellcode Runner/Injector in Rust using NTDLL functions directly with the ntapi Library
Shellcode Runner/Injector in Rust using NTDLL functions directly with the ntapi Library

RustSCRunner Shellcode Runner/Injector in Rust using NTDLL functions directly with the ntapi Library. Surprisingly this is my first ever Rust project

Universal Windows library for discovering common render engines functions. Supports DirectX9 (D3D9), DirectX10 (D3D10), DirectX11 (D3D11), DirectX12 (D3D12).
Universal Windows library for discovering common render engines functions. Supports DirectX9 (D3D9), DirectX10 (D3D10), DirectX11 (D3D11), DirectX12 (D3D12).

Shroud Universal library for discovering common render engines functions. Supports DirectX9 (D3D9), DirectX10 (D3D10), DirectX11 (D3D11), DirectX12 (D

Utility library for some Lenovo IdeaPad laptops. Supports IdeaPad Intel and AMD Models (15IIL05 and 15ARE05)

ideapad A Rust utility library for some Lenovo IdeaPad specific functionality. A Fair Warning This crate calls raw ACPI methods, which on the best cas

Patch binary file using IDA signatures and defined replacement bytes in YAML.

fabricbin Patch binary file using IDA signatures and defined replacement bytes in YAML. Install: cargo install --git https://github.com/makindotcc/fab

makin 3 Oct 24, 2023
A diff-based data management language to implement unlimited undo, auto-save for games, and cloud-apps which needs to retain every change.

Docchi is a diff-based data management language to implement unlimited undo, auto-save for games, and cloud-apps which needs to save very often. User'

juzy 21 Sep 19, 2022
A syntax-highlighting pager for git, diff, and grep output

Get Started Install delta and add this to your ~/.gitconfig: [core] pager = delta [interactive] diffFilter = delta --color-only [delta]

Dan Davison 16k Dec 31, 2022
Watch output and trigger on diff!

watchdiff Watch output and trigger on diff! Ever want to have watch output only tell you what changed? And not only what, but when? Now you can! Enter

geno 2 Apr 6, 2022
A truly zero-dependency crate providing quick, easy, reliable, and scalable access to the name "jordin"

jordin Finally! A truly zero-dependency crate providing quick, easy, reliable, and scalable access to the name "jordin". Additionally, this one-of-a-k

jordin 2 Aug 4, 2022
A crate providing a MemoryCell struct, which stores a current and previous value.

memcell What is a MemoryCell? A MemoryCell is a struct containing both a current and optional previous value. Definition #[derive(Debug, Clone)] pub s

Imajin 9 Nov 21, 2022
Rust-battery - Rust crate providing cross-platform information about the notebook batteries.

battery Rust crate providing cross-platform information about the notebook batteries. Table of contents Overview Supported platforms Install Examples

svartalf 326 Dec 21, 2022
An LLM-powered (CodeLlama or OpenAI) local diff code review tool.

augre An LLM-powered (CodeLlama or OpenAI) local diff code review tool. Binary Usage Install Windows: $ iwr https://github.com/twitchax/augre/releases

Aaron Roney 4 Oct 19, 2023
A lightweight command line utility with some small functions for CTFs.

Ice Ice is a lightweight command line utility to help with simple problems encountered while playing CTFs. Extracted from graveyard NOTE: Most of the

Aquib 12 Dec 19, 2022
argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

argmax argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper w

David Peter 22 Nov 20, 2022