pub struct BatchResult {
pub results: Vec<(PathBuf, Result<PatchResult, PatchError>)>,
}Expand description
The result of applying a batch of patches to a directory.
This struct is returned by apply_patches_to_dir() and aggregates the results
for each individual patch operation. It allows you to check for “hard” errors
(like I/O issues) separately from “soft” errors (like a hunk failing to apply).
§Example
let dir = tempdir()?;
fs::write(dir.path().join("file1.txt"), "foo\n")?;
fs::write(dir.path().join("file2.txt"), "baz\n")?;
let diff = r#"
```diff
--- a/file1.txt
+++ b/file1.txt
@@ -1 +1 @@
-foo
+bar
--- a/file2.txt
+++ b/file2.txt
@@ -1 +1 @@
-WRONG
+qux
```
"#;
let patches = parse_auto(diff)?;
let options = ApplyOptions::exact();
let batch_result = apply_patches_to_dir(&patches, dir.path(), options);
// The overall batch succeeded (no I/O errors).
assert!(batch_result.all_succeeded());
// But we can inspect individual results for partial failures.
for (path, result) in &batch_result.results {
let patch_result = result.as_ref().unwrap();
if path.to_str() == Some("file1.txt") {
assert!(patch_result.report.all_applied_cleanly());
} else {
assert!(!patch_result.report.all_applied_cleanly());
}
}Fields§
§results: Vec<(PathBuf, Result<PatchResult, PatchError>)>A list of results for each patch operation attempted. Each entry is a tuple of the target file path and the result of the operation.
Implementations§
Source§impl BatchResult
impl BatchResult
Sourcepub fn all_succeeded(&self) -> bool
pub fn all_succeeded(&self) -> bool
Checks if all patches in the batch were applied without “hard” errors (like I/O errors).
This does not check if all hunks were applied cleanly. For that, you must
inspect the individual PatchResult objects.
§Example
let dir = tempdir()?;
fs::write(dir.path().join("file1.txt"), "foo\n")?;
// Note: file2.txt does not exist, which will cause a hard error.
let diff = r#"
```diff
--- a/file1.txt
+++ b/file1.txt
@@ -1 +1 @@
-foo
+bar
--- a/file2.txt
+++ b/file2.txt
@@ -1 +1 @@
-baz
+qux
```
"#;
let patches = parse_auto(diff)?;
let options = ApplyOptions::new();
let batch_result = apply_patches_to_dir(&patches, dir.path(), options);
// The batch did not fully succeed because of the missing file.
assert!(!batch_result.all_succeeded());Sourcepub fn hard_failures(&self) -> Vec<(&PathBuf, &PatchError)>
pub fn hard_failures(&self) -> Vec<(&PathBuf, &PatchError)>
Returns a list of all operations that resulted in a “hard” error (e.g., I/O).
This method is useful for isolating critical failures that prevented a patch
from being attempted, such as file system errors, permission issues, or
security violations. It filters the results to only include Err variants,
providing a direct way to report or handle unrecoverable problems in a batch
run.
§Example
let batch_result = apply_patches_to_dir(&patches, dir.path(), ApplyOptions::new());
// Check for any hard failures in the batch.
let failures = batch_result.hard_failures();
assert_eq!(failures.len(), 1);
assert_eq!(failures[0].0.to_str(), Some("missing.txt"));
assert!(matches!(failures[0].1, PatchError::TargetNotFound(_)));Trait Implementations§
Auto Trait Implementations§
impl Freeze for BatchResult
impl !RefUnwindSafe for BatchResult
impl Send for BatchResult
impl Sync for BatchResult
impl Unpin for BatchResult
impl UnsafeUnpin for BatchResult
impl !UnwindSafe for BatchResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more