pub struct HunkFailure {
pub hunk_index: usize,
pub reason: HunkApplyError,
}Expand description
Details about a hunk that failed to apply.
This struct is returned by ApplyResult::failures() and provides a convenient
way to inspect which hunk failed and for what reason.
§Example
let original_content = "line 1\n";
let diff = r#"
```diff
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-WRONG CONTEXT
+line 1
```
"#;
let patch = parse_single_patch(diff)?;
let options = ApplyOptions::exact();
let result = apply_patch_to_content(&patch, Some(original_content), &options);
let failures: Vec<HunkFailure> = result.report.failures();
assert_eq!(failures.len(), 1);
let failure = &failures[0];
assert_eq!(failure.hunk_index, 1); // 1-based index
assert!(matches!(failure.reason, HunkApplyError::ContextNotFound));Fields§
§hunk_index: usizeThe 1-based index of the hunk that failed.
reason: HunkApplyErrorThe reason for the failure.
Trait Implementations§
Source§impl Clone for HunkFailure
impl Clone for HunkFailure
Source§fn clone(&self) -> HunkFailure
fn clone(&self) -> HunkFailure
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HunkFailure
impl Debug for HunkFailure
Source§impl PartialEq for HunkFailure
impl PartialEq for HunkFailure
impl StructuralPartialEq for HunkFailure
Auto Trait Implementations§
impl Freeze for HunkFailure
impl RefUnwindSafe for HunkFailure
impl Send for HunkFailure
impl Sync for HunkFailure
impl Unpin for HunkFailure
impl UnsafeUnpin for HunkFailure
impl UnwindSafe for HunkFailure
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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 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>
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