Expand description
Fast diff/patch engine built on imara-diff
(Apache-2.0), the diff engine that powers gitoxide. This crate adds:
- Word- and char-granularity tokenization (
imara-diffonly ships line tokenization out of the box). - A
jsdiff-shapedChangeresult type (unchanged/added/removed runs across the whole input, not just the changed hunks), so the npm binding can offer an easy migration path from the incumbentdiffpackage it measurably outperforms.
See the repository README for the real, reproducible benchmark against jsdiff.
Structs§
- Change
- One contiguous run of tokens in a diff result: unchanged (present
identically in both
beforeandafter), added, or removed. Mirrors jsdiff’sChangeshape ({value, added, removed, count}) so the npm binding can expose an API shaped like the incumbent it’s meant to be an easy migration from.
Enums§
- Algorithm
imara-diffsupports multiple different algorithms for computing an edit sequence. These algorithms have different performance and all produce different output.
Functions§
- char_
diff - Diffs
before/aftercharacter by character. - line_
diff - Diffs
before/afterline by line (the newline is included in each line’s token, same conventionimara-diffuses, so changing the final line’s trailing newline is itself detected as a change). - line_
diff_ many - Diffs many
(before, after)pairs at once, across a Rayon thread pool. - unified_
diff - Renders a unified diff (
git diff/diff -ustyle patch text) forbefore/after. Thin wrapper overimara-diff’s ownunified_difffeature – no reimplementation needed here, unlike the tokenizers above. - word_
diff - Diffs
before/afterword by word. “Word” means a maximal run of alphanumeric/_characters; runs of whitespace/punctuation between words are their own tokens, so e.g. a single added space is reported as its own small change rather than merged into a neighboring word.