Skip to main content

Hunk

Struct Hunk 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional 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

Source

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.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.