pub struct Hunk {
pub lines: Vec<String>,
}
Expand description
Represents a single hunk of changes within a patch.
A hunk corresponds to a block of lines starting with @@ ... @@
in a
unified diff. It contains the context, added, and removed lines.
Fields§
§lines: Vec<String>
The raw lines of the hunk, each prefixed with ’ ’, ‘+’, or ‘-’.
Implementations§
Source§impl Hunk
impl Hunk
Sourcepub fn get_match_block(&self) -> Vec<&str>
pub fn get_match_block(&self) -> Vec<&str>
Extracts the lines that need to be matched in the target file.
This includes context lines (starting with ’ ’) and deletion lines (starting with ‘-’). The leading character is stripped.
§Example
let hunk = Hunk {
lines: vec![
" context".to_string(),
"-deleted".to_string(),
"+added".to_string(),
],
};
assert_eq!(hunk.get_match_block(), vec!["context", "deleted"]);
Sourcepub fn get_replace_block(&self) -> Vec<&str>
pub fn get_replace_block(&self) -> Vec<&str>
Extracts the lines that will replace the matched block in the target file.
This includes context lines (starting with ’ ’) and addition lines (starting with ‘+’). The leading character is stripped.
§Example
let hunk = Hunk {
lines: vec![
" context".to_string(),
"-deleted".to_string(),
"+added".to_string(),
],
};
assert_eq!(hunk.get_replace_block(), vec!["context", "added"]);
Sourcepub fn has_changes(&self) -> bool
pub fn has_changes(&self) -> bool
Checks if the hunk contains any effective changes (additions or deletions).
A hunk with only context lines has no changes.
§Examples
let hunk_with_changes = Hunk {
lines: vec![ "+ a".to_string() ],
};
assert!(hunk_with_changes.has_changes());
let hunk_without_changes = Hunk {
lines: vec![ " a".to_string() ],
};
assert!(!hunk_without_changes.has_changes());
Trait Implementations§
impl Eq for Hunk
impl StructuralPartialEq for Hunk
Auto Trait Implementations§
impl Freeze for Hunk
impl RefUnwindSafe for Hunk
impl Send for Hunk
impl Sync for Hunk
impl Unpin for Hunk
impl UnwindSafe for Hunk
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