Patcher
A Rust library for generating and applying Git-style unified diff patches. See 中文说明.
Tutorial
See Tutorial.
Features
- Generate patches from original and modified content
- Apply patches to content, both forward and in reverse
- Parse patches from text format
- Support for multi-file patches
- Command-line interface for generating and applying patches
- Efficient Myers diff algorithm implementation
- Customizable diff implementation for any data type
Installation
Add to your Cargo.toml:
[]
= { = "0.1.0", = false }
Or install the CLI tool:
Library Usage
Generate a Patch
use ;
Apply a Patch
use ;
Parse a Patch
use Patch;
Working with Multi-file Patches
use ;
use Path;
Data Structures
Patch
: Represents a complete diff between two filesChunk
: Represents a contiguous section of changesOperation
: Represents a single line in a diff (addition, deletion, or context)MultifilePatch
: Collection of patches for multiple filesMultifilePatcher
: Applies multiple patches to filesDiff
: Trait for implementing custom diff logicmyers_diff
: Function to apply the efficient Myers algorithm to custom sequence types
Limitations
- Limited support for various diff formats (focuses on git-style diffs)
License
This project is distributed under the terms of MIT.
See LICENSE for details.
Copyright 2025 Tyr Chen