Skip to main content

FileDiff

Struct FileDiff 

Source
pub struct FileDiff {
    pub old_path: Option<String>,
    pub new_path: Option<String>,
    pub status: FileStatus,
    pub binary: bool,
    pub similarity: Option<u8>,
    pub old_mode: Option<String>,
    pub new_mode: Option<String>,
    pub hunks: Vec<Hunk>,
    pub header: Vec<String>,
    pub coarse: bool,
    /* private fields */
}
Expand description

The changes to one file.

Fields§

§old_path: Option<String>

Path before the change (None for an added file); a/ and b/ prefixes are stripped.

§new_path: Option<String>

Path after the change (None for a deleted file).

§status: FileStatus§binary: bool

A binary file: no hunks, only a marker.

§similarity: Option<u8>

similarity index of a rename or copy, in percent.

§old_mode: Option<String>§new_mode: Option<String>§hunks: Vec<Hunk>§header: Vec<String>

The header lines as written (diff --git, index, ---, +++, binary data…), without line breaks; FileDiff::to_patch writes them back verbatim.

§coarse: bool

The diff hit its cost cap: correct, but not necessarily the smallest.

Implementations§

Source§

impl FileDiff

Source

pub fn from_texts(old: &str, new: &str) -> FileDiff

Diffs two texts line by line with the default options.

Source

pub fn from_texts_with(old: &str, new: &str, opts: DiffOptions) -> FileDiff

Diffs two texts line by line. The new text is kept, so every Gap is expandable.

Source

pub fn with_paths(self, old: &str, new: &str) -> FileDiff

Sets both paths (and the ---/+++ header lines).

Source

pub fn with_source(self, new_text: &str) -> FileDiff

Supplies the full new text of a parsed patch, so its collapsed ranges can be expanded.

Source

pub fn path(&self) -> &str

The path to show: the new one, else the old one.

Source

pub fn stats(&self) -> (usize, usize)

Lines added and removed.

Source

pub fn source_len(&self) -> Option<u32>

Number of lines of the new text, when it is known.

Source

pub fn source_line(&self, new_no: u32) -> Option<&str>

Line new_no (1-based) of the new text, without its line break, when the text is known.

Source

pub fn gaps(&self) -> Vec<Gap>

The unchanged ranges around the hunks, in order. The range after the last hunk is listed only when the new text is known (a patch does not say how long the file is). Empty ranges are left out.

Source

pub fn to_patch(&self) -> String

This file as a unified patch: the header lines, then the hunks.

Trait Implementations§

Source§

impl Clone for FileDiff

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileDiff

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FileDiff

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for FileDiff

Source§

impl PartialEq for FileDiff

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FileDiff

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.