java-diff-utils-rs
Experimental preview release of a Rust port of the core diffing and patching behavior behind java-diff-utils.
This project aims to provide Java-compatible diff semantics in a safe, idiomatic Rust implementation while keeping the public API approachable for users who want patch generation, text diffing, and unified diff support without unsafe Rust code.
Release status
This is an experimental alpha release.
The crate is intended for early adopters and maintainers who want to evaluate the Rust port against the upstream Java project. The public API is intentionally focused on correctness and parity rather than making unsupported speed claims. Performance benchmarking is ongoing and the long-running algorithm benchmark is kept ignored by default so normal test runs stay fast.
Overview
This crate includes:
MyersDiff: classic quadratic-space Myers algorithmMyersDiffWithLinearSpace: linear-space Myers variant for larger inputsHistogramDiff: anchor-based diff path with fallback behavior for tricky sequences- patch generation and application helpers
- unified diff parsing and writing support
- inline and side-by-side diff row generation
The project is structured around a small set of clearly separated layers:
src/algorithm/: diff algorithm implementations and factoriessrc/patch/: deltas, chunk verification, and patch applicationsrc/text/: diff row generation and string utilitiessrc/unifieddiff/: unified diff readers and writerssrc/diff_utils.rs: public convenience helpers and default selection points
Safety and idiomatic constraints
The crate intentionally enforces a no-unsafe policy:
#![forbid(unsafe_code)]at the crate root and binary entry points- no raw pointer arithmetic or unsafe memory aliasing
- explicit ownership and borrowing patterns
- bounded, predictable workspace allocation strategies
Quick start
use ;
use DiffAlgorithm;
let original = vec!;
let revised = vec!;
let changes = default.diff;
let patch = generate;
let applied = patch.apply_to.unwrap;
assert_eq!;
let histogram_changes = new.diff;
assert!;
Upstream Java parity check
The port was validated against the official java-diff-utils reference library in Docker using the same representative edit scenario.
Java reference output:
delta_count=1
CHANGE src=1:1 tgt=1:1
The Rust implementation matches the same semantic result for the equivalent diff case.
Performance notes
The implementation is designed to balance correctness and efficiency, but this project does not yet make a blanket claim that it is faster than Java. Performance measurement is ongoing, and the long-running algorithm benchmark is intentionally ignored by default so the standard validation loop stays practical for day-to-day development.
Benchmarking
Use Criterion to compare the available algorithms when you want to run the longer benchmark intentionally:
The benchmark exercises:
- public API diffing
- Myers quadratic vs linear-space behavior
- histogram diff behavior on similar and pathological inputs
Testing
The detailed test matrix and validation commands live in TESTS.md.
The standard project verification command is:
License
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.