9 releases (breaking)

0.7.0 Dec 28, 2022
0.6.0 Jan 12, 2022
0.5.0 Feb 13, 2019
0.4.2 Sep 7, 2017
0.4.1 Nov 25, 2016

#773 in Parser implementations

Download history 1904/week @ 2024-07-19 2265/week @ 2024-07-26 2035/week @ 2024-08-02 2510/week @ 2024-08-09 2107/week @ 2024-08-16 1889/week @ 2024-08-23 1876/week @ 2024-08-30 2089/week @ 2024-09-06 1726/week @ 2024-09-13 2020/week @ 2024-09-20 2032/week @ 2024-09-27 1847/week @ 2024-10-04 1683/week @ 2024-10-11 2001/week @ 2024-10-18 1717/week @ 2024-10-25 1466/week @ 2024-11-01

7,231 downloads per month
Used in 14 crates (12 directly)

MIT license

36KB
697 lines

Patch

Checks Crates.io Badge docs.rs Lines of Code

Rust crate for parsing and producing patch files in the Unified Format.

The parser attempts to be forgiving enough to be compatible with diffs produced by programs like git. It accomplishes this by ignoring the additional code context and information provided in the diff by those programs.

See the Documentation for more information and for examples.


lib.rs:

Parse and produce patch files (diffs) in the Unified Format.

The format is not fully specified, but people like Guido van Rossum have done the work to figure out the details.

The parser attempts to be forgiving enough to be compatible with diffs produced by programs like git. It accomplishes this by ignoring the additional code context and information provided in the diff by those programs.

Example

// Make sure you add the `patch` crate to the `[dependencies]` key of your Cargo.toml file.
use patch::Patch;

let sample = "\
--- before.py
+++ path/to/after.py
@@ -1,4 +1,4 @@
-bacon
-eggs
-ham
+python
+eggy
+hamster
 guido\n";

let patch = Patch::from_single(sample)?;
assert_eq!(&patch.old.path, "before.py");
assert_eq!(&patch.new.path, "path/to/after.py");

// Print out the parsed patch file in its Rust representation
println!("{:#?}", patch);

// Print out the parsed patch file in the Unified Format. For input that was originally in the
// Unified Format, this will produce output identical to that original input.
println!("{}", patch); // use format!("{}\n", patch) to get this as a String

Dependencies

~2.5MB
~38K SLoC