Skip to main content

FileDiff

Struct FileDiff 

Source
pub struct FileDiff {
    pub path: PathBuf,
    pub old_path: Option<PathBuf>,
    pub is_deleted: bool,
    pub hunks: Vec<Hunk>,
}
Expand description

A file diff containing all hunks for a single file

Fields§

§path: PathBuf

Path to the file (new path if renamed)

§old_path: Option<PathBuf>

Original path (if renamed)

§is_deleted: bool

Whether the file was deleted in this diff

§hunks: Vec<Hunk>

Hunks in this file diff

Implementations§

Source§

impl FileDiff

Source

pub fn new(path: PathBuf) -> Self

Creates a new file diff

§Arguments
  • path - Path to the file
§Returns

A new FileDiff with empty hunks

§Examples
use std::path::PathBuf;

use rust_diff_analyzer::git::FileDiff;

let diff = FileDiff::new(PathBuf::from("src/lib.rs"));
assert!(diff.hunks.is_empty());
Source

pub fn total_added(&self) -> usize

Returns total number of added lines

§Returns

Sum of added lines across all hunks

§Examples
use std::path::PathBuf;

use rust_diff_analyzer::git::FileDiff;

let diff = FileDiff::new(PathBuf::from("src/lib.rs"));
assert_eq!(diff.total_added(), 0);
Source

pub fn total_removed(&self) -> usize

Returns total number of removed lines

§Returns

Sum of removed lines across all hunks

§Examples
use std::path::PathBuf;

use rust_diff_analyzer::git::FileDiff;

let diff = FileDiff::new(PathBuf::from("src/lib.rs"));
assert_eq!(diff.total_removed(), 0);
Source

pub fn all_added_lines(&self) -> Vec<usize>

Returns all added line numbers

§Returns

Vector of all added line numbers

§Examples
use std::path::PathBuf;

use rust_diff_analyzer::git::FileDiff;

let diff = FileDiff::new(PathBuf::from("src/lib.rs"));
assert!(diff.all_added_lines().is_empty());
Source

pub fn all_removed_lines(&self) -> Vec<usize>

Returns all removed line numbers

§Returns

Vector of all removed line numbers

§Examples
use std::path::PathBuf;

use rust_diff_analyzer::git::FileDiff;

let diff = FileDiff::new(PathBuf::from("src/lib.rs"));
assert!(diff.all_removed_lines().is_empty());
Source

pub fn all_removed_positions_in_new(&self) -> Vec<usize>

Returns new-file line positions of all removals across hunks

See Hunk::removed_positions_in_new for the attribution rule.

§Returns

Vector of new-file line numbers, one per removed line

§Examples
use std::path::PathBuf;

use rust_diff_analyzer::git::FileDiff;

let diff = FileDiff::new(PathBuf::from("src/lib.rs"));
assert!(diff.all_removed_positions_in_new().is_empty());
Source

pub fn is_rust_file(&self) -> bool

Checks if file path ends with .rs extension

§Returns

true if file is a Rust source file

§Examples
use std::path::PathBuf;

use rust_diff_analyzer::git::FileDiff;

let diff = FileDiff::new(PathBuf::from("src/lib.rs"));
assert!(diff.is_rust_file());

let diff = FileDiff::new(PathBuf::from("README.md"));
assert!(!diff.is_rust_file());

Trait Implementations§

Source§

impl Clone for FileDiff

Source§

fn clone(&self) -> FileDiff

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 Eq for FileDiff

Source§

impl PartialEq for FileDiff

Source§

fn eq(&self, other: &FileDiff) -> 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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.