pub enum HunkApplyError {
ContextNotFound,
AmbiguousExactMatch(Vec<usize>),
AmbiguousFuzzyMatch(Vec<(usize, usize)>),
FuzzyMatchBelowThreshold {
best_score: f64,
threshold: f32,
location: HunkLocation,
},
}Expand description
The reason a hunk failed to apply.
This enum provides specific details about why a hunk could not be applied to the
target content. It is found within the HunkApplyStatus::Failed variant.
§Example
use mpatch::{apply_patch_to_content, parse_single_patch, ApplyOptions, HunkApplyStatus, HunkApplyError};
let original_content = "line 1\nline 2\n";
// This patch will fail because the context is wrong.
let diff = r#"
```diff
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
line 1
-WRONG CONTEXT
+line two
```
"#;
let patch = parse_single_patch(diff)?;
let options = ApplyOptions::exact();
let result = apply_patch_to_content(&patch, Some(original_content), &options);
// We can inspect the status of the first hunk.
let hunk_status = &result.report.hunk_results[0];
assert!(matches!(hunk_status, HunkApplyStatus::Failed(HunkApplyError::ContextNotFound)));Variants§
ContextNotFound
The context lines for the hunk could not be found in the target file.
AmbiguousExactMatch(Vec<usize>)
An exact match for the hunk’s context was found in multiple locations, and the ambiguity could not be resolved by the line number hint.
AmbiguousFuzzyMatch(Vec<(usize, usize)>)
A fuzzy match for the hunk’s context was found in multiple locations with the same top score, and the ambiguity could not be resolved.
FuzzyMatchBelowThreshold
The best fuzzy match found was below the required similarity threshold.
Trait Implementations§
Source§impl Clone for HunkApplyError
impl Clone for HunkApplyError
Source§fn clone(&self) -> HunkApplyError
fn clone(&self) -> HunkApplyError
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 HunkApplyError
impl Debug for HunkApplyError
Source§impl Display for HunkApplyError
impl Display for HunkApplyError
Source§impl Error for HunkApplyError
impl Error for HunkApplyError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl PartialEq for HunkApplyError
impl PartialEq for HunkApplyError
impl StructuralPartialEq for HunkApplyError
Auto Trait Implementations§
impl Freeze for HunkApplyError
impl RefUnwindSafe for HunkApplyError
impl Send for HunkApplyError
impl Sync for HunkApplyError
impl Unpin for HunkApplyError
impl UnsafeUnpin for HunkApplyError
impl UnwindSafe for HunkApplyError
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