pub fn parse_patches(content: &str) -> Result<Vec<Patch>, ParseError>Expand description
Parses a string containing raw unified diff content into a vector of Patch objects.
Unlike parse_diffs(), this function does not look for markdown code blocks.
It assumes the entire input string is valid unified diff content. This is useful
when you have a raw .diff or .patch file, or the output of a git diff command.
For automatic format detection, use parse_auto().
§Arguments
content- A string slice containing the raw unified diff to parse.
§Errors
Returns Err(ParseError::MissingFileHeader) if the content contains patch
hunks but no --- a/path/to/file header.
§Example
use mpatch::parse_patches;
let raw_diff = r#"
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,3 @@
fn main() {
- println!("Hello, world!");
+ println!("Hello, mpatch!");
}
"#;
let patches = parse_patches(raw_diff).unwrap();
assert_eq!(patches.len(), 1);
assert_eq!(patches[0].file_path.to_str(), Some("src/main.rs"));