#[non_exhaustive]pub struct Hunk {
pub old_start: usize,
pub old_count: usize,
pub new_start: usize,
pub new_count: usize,
pub lines: Vec<DiffLine>,
pub missing_newline_at: Vec<usize>,
}Expand description
A hunk in a unified diff
Produced by FileDiff::hunks; build one by hand with Hunk::new.
#[non_exhaustive] so fields can be added without breaking downstream
crates again.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.old_start: usize§old_count: usize§new_start: usize§new_count: usize§lines: Vec<DiffLine>§missing_newline_at: Vec<usize>Indices into lines that must be followed by NO_NEWLINE_MARKER;
see FileDiff::missing_newline_at.
Implementations§
Source§impl Hunk
impl Hunk
Sourcepub fn new(
old_start: usize,
old_count: usize,
new_start: usize,
new_count: usize,
lines: Vec<DiffLine>,
missing_newline_at: Vec<usize>,
) -> Self
pub fn new( old_start: usize, old_count: usize, new_start: usize, new_count: usize, lines: Vec<DiffLine>, missing_newline_at: Vec<usize>, ) -> Self
Assemble a hunk. missing_newline_at indexes lines.
Sourcepub fn header(&self) -> String
pub fn header(&self) -> String
The @@ -a,b +c,d @@ header line (no trailing newline).
An empty range is numbered the way diff -u and git diff number
it: by the line after which it sits, so an added file’s old side
is -0,0 and a zero-context insertion after line 3 is -3,0. The
struct fields keep the 1-based position of the next line.
Sourcepub fn unified_lines(&self) -> Vec<String>
pub fn unified_lines(&self) -> Vec<String>
The hunk as unified-diff lines without trailing newlines: the header,
then each /+/- prefixed line, with NO_NEWLINE_MARKER after
any line whose side of the file ended there without a terminator.
Every renderer that prints hunk bodies should go through this so the applicator-facing details (prefixes, markers) cannot drift apart.
Auto Trait Implementations§
impl Forget for Hunk
impl Freeze for Hunk
impl Move for Hunk
impl RefUnwindSafe for Hunk
impl Send for Hunk
impl Sync for Hunk
impl Unpin for Hunk
impl UnsafeUnpin 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
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> ⓘ
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> ⓘ
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