pub struct Hunk {
pub file_path: PathBuf,
pub old_start: u32,
pub old_count: u32,
pub new_start: u32,
pub new_count: u32,
pub lines: Vec<HunkLine>,
}Expand description
One @@ hunk from a unified diff, with its file.
Fields§
§file_path: PathBuf§old_start: u32§old_count: u32§new_start: u32§new_count: u32§lines: Vec<HunkLine>Implementations§
Source§impl Hunk
impl Hunk
Sourcepub fn numbered_lines(&self) -> impl Iterator<Item = (Option<u32>, &HunkLine)>
pub fn numbered_lines(&self) -> impl Iterator<Item = (Option<u32>, &HunkLine)>
Every line in the hunk paired with its new-file line number, or None
for a Removed line.
This is the single implementation of the line-numbering rule, and
everything that needs a line number goes through it. Numbering starts
at new_start and advances for each Context or Added line;
Removed lines do not advance it, because they do not exist in the new
file at all.
That rule is what Payload::valid_lines rests on, and therefore what
decides whether an LLM finding gets attributed to the right code. It
previously existed twice — once here and once inline in the renderer —
which meant hardening one did nothing for the other.
Sourcepub fn numbered_new_lines(&self) -> impl Iterator<Item = (u32, &str)>
pub fn numbered_new_lines(&self) -> impl Iterator<Item = (u32, &str)>
Just the lines that exist in the new file, with their line numbers.
A projection of Self::numbered_lines, not a second walk: callers
that only care about real file lines (checking a parse against the file
on disk, say) get them without restating how numbering works.
Sourcepub fn whole_file(file_path: PathBuf, content: &str) -> Hunk
pub fn whole_file(file_path: PathBuf, content: &str) -> Hunk
Build a synthetic hunk covering an entire file’s content, for
drep check PATHS where there is no diff to consult.
Every line is Context and numbering starts at 1, so the renderer
walks it with the same numbered_lines iterator it uses for a real
hunk. It also selects the whole-file scope sentence, because no line is
added or removed — an inference that holds because git never emits a
hunk with no changed line: hunks exist only around changes. That
property is load-bearing and is stated here because it belongs to an
external tool rather than to this type.
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 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.