Skip to main content

BatchResult

Struct BatchResult 

Source
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

Source

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());
Source

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§

Source§

impl Debug for BatchResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.