pub enum HunkApplyStatus {
Applied {
location: HunkLocation,
match_type: MatchType,
replaced_lines: Vec<String>,
},
SkippedNoChanges,
Failed(HunkApplyError),
}Expand description
The result of applying a single hunk.
This enum is returned by apply_hunk_to_lines() and is the item type for the
HunkApplier iterator. It provides a detailed outcome for each individual
hunk within a patch.
§Example
use mpatch::{apply_hunk_to_lines, parse_single_patch, ApplyOptions, HunkApplyStatus, HunkApplyError};
let diff = r#"
```diff
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
line 1
-line 2
+line two
```
"#;
let hunk = parse_single_patch(diff)?.hunks.remove(0);
let options = ApplyOptions::new();
// --- Success Case ---
let mut lines_success = vec!["line 1".to_string(), "line 2".to_string()];
let status_success = apply_hunk_to_lines(&hunk, &mut lines_success, &options);
assert!(matches!(status_success, HunkApplyStatus::Applied { .. }));
assert_eq!(lines_success, vec!["line 1", "line two"]);
// --- Failure Case ---
let mut lines_fail = vec!["wrong".to_string(), "content".to_string()];
let fail_status = apply_hunk_to_lines(&hunk, &mut lines_fail, &options);
assert!(matches!(fail_status, HunkApplyStatus::Failed(HunkApplyError::FuzzyMatchBelowThreshold { .. })));
assert_eq!(lines_fail, vec!["wrong", "content"]); // Content is unchangedVariants§
Applied
The hunk was applied successfully.
Fields
§
location: HunkLocationThe location where the hunk was applied.
SkippedNoChanges
The hunk was skipped because it contained no effective changes.
Failed(HunkApplyError)
The hunk failed to apply for the specified reason.
Trait Implementations§
Source§impl Clone for HunkApplyStatus
impl Clone for HunkApplyStatus
Source§fn clone(&self) -> HunkApplyStatus
fn clone(&self) -> HunkApplyStatus
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 HunkApplyStatus
impl Debug for HunkApplyStatus
Source§impl PartialEq for HunkApplyStatus
impl PartialEq for HunkApplyStatus
impl StructuralPartialEq for HunkApplyStatus
Auto Trait Implementations§
impl Freeze for HunkApplyStatus
impl RefUnwindSafe for HunkApplyStatus
impl Send for HunkApplyStatus
impl Sync for HunkApplyStatus
impl Unpin for HunkApplyStatus
impl UnsafeUnpin for HunkApplyStatus
impl UnwindSafe for HunkApplyStatus
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