pub enum MatchType {
Exact,
ExactIgnoringWhitespace,
Fuzzy {
score: f64,
},
}Expand description
Describes the method used to successfully locate and apply a hunk.
This enum is included in the HunkApplyStatus::Applied variant and provides
insight into how mpatch found the location for a hunk, which is useful for
logging and diagnostics.
§Example
use mpatch::{apply_patch_to_content, parse_single_patch, ApplyOptions, HunkApplyStatus, MatchType};
// The file content has an extra space, which will prevent an `Exact` match.
let original_content = "line 1 \nline 2\n";
let diff = r#"
```diff
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1,2 @@
line 1
-line 2
+line two
```
"#;
let patch = parse_single_patch(diff)?;
let options = ApplyOptions::new();
let result = apply_patch_to_content(&patch, Some(original_content), &options);
let hunk_status = &result.report.hunk_results[0];
assert!(matches!(hunk_status, HunkApplyStatus::Applied { match_type: MatchType::ExactIgnoringWhitespace, .. }));Variants§
Exact
An exact, character-for-character match of the context/deletion lines.
ExactIgnoringWhitespace
An exact match after ignoring trailing whitespace on each line.
Fuzzy
A fuzzy match found using a similarity algorithm.
Trait Implementations§
impl StructuralPartialEq for MatchType
Auto Trait Implementations§
impl Freeze for MatchType
impl RefUnwindSafe for MatchType
impl Send for MatchType
impl Sync for MatchType
impl Unpin for MatchType
impl UnsafeUnpin for MatchType
impl UnwindSafe for MatchType
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