patch_apply/
lib.rs

1//! Parse and produce patch files (diffs) in the [Unified Format].
2//!
3//! The format is not fully specified, but people like Guido van Rossum [have done the work][spec]
4//! to figure out the details.
5//!
6//! The parser attempts to be forgiving enough to be compatible with diffs produced by programs
7//! like git. It accomplishes this by ignoring the additional code context and information provided
8//! in the diff by those programs.
9//!
10//! ## Example
11//!
12//! ```
13//! # fn main() -> Result<(), patch::ParseError<'static>> {
14//! // Make sure you add the `patch` crate to the `[dependencies]` key of your Cargo.toml file.
15//! use patch::Patch;
16//!
17//! let sample = "\
18//! --- before.py
19//! +++ path/to/after.py
20//! @@ -1,4 +1,4 @@
21//! -bacon
22//! -eggs
23//! -ham
24//! +python
25//! +eggy
26//! +hamster
27//!  guido\n";
28//!
29//! let patch = Patch::from_single(sample)?;
30//! assert_eq!(&patch.old.path, "before.py");
31//! assert_eq!(&patch.new.path, "path/to/after.py");
32//!
33//! // Print out the parsed patch file in its Rust representation
34//! println!("{:#?}", patch);
35//!
36//! // Print out the parsed patch file in the Unified Format. For input that was originally in the
37//! // Unified Format, this will produce output identical to that original input.
38//! println!("{}", patch); // use format!("{}\n", patch) to get this as a String
39//! # Ok(())
40//! # }
41//! ```
42//!
43//! [Unified Format]: https://www.gnu.org/software/diffutils/manual/html_node/Unified-Format.html
44//! [spec]: http://www.artima.com/weblogs/viewpost.jsp?thread=164293
45
46#![deny(unused_must_use)]
47
48mod apply;
49mod ast;
50mod parser;
51
52pub use apply::*;
53pub use ast::*;
54pub use parser::ParseError;