BlameRanges

Enum BlameRanges 

Source
pub enum BlameRanges {
    WholeFile,
    PartialFile(Vec<Range<u32>>),
}
Expand description

A type to represent one or more line ranges to blame in a file.

It handles the conversion between git’s 1-based inclusive ranges and the internal 0-based exclusive ranges used by the blame algorithm.

§Examples

use gix_blame::BlameRanges;

// Blame lines 20 through 40 (inclusive)
let range = BlameRanges::from_one_based_inclusive_range(20..=40);

// Blame multiple ranges
let mut ranges = BlameRanges::from_one_based_inclusive_ranges(vec![
    1..=4, // Lines 1-4
   10..=14, // Lines 10-14
]
);

§Line Number Representation

This type uses 1-based inclusive ranges to mirror git’s behaviour:

  • A range of 20..=40 represents 21 lines, spanning from line 20 up to and including line 40
  • This will be converted to 19..40 internally as the algorithm uses 0-based ranges that are exclusive at the end

§Empty Ranges

You can blame the entire file by calling BlameRanges::default(), or by passing an empty vector to from_one_based_inclusive_ranges.

Variants§

§

WholeFile

Blame the entire file.

§

PartialFile(Vec<Range<u32>>)

Blame ranges in 0-based exclusive format.

Implementations§

Source§

impl BlameRanges

Lifecycle

Source

pub fn from_one_based_inclusive_range( range: RangeInclusive<u32>, ) -> Result<Self, Error>

Create from a single 0-based range.

Note that the input range is 1-based inclusive, as used by git, and the output is a zero-based BlameRanges instance.

Source

pub fn from_one_based_inclusive_ranges( ranges: Vec<RangeInclusive<u32>>, ) -> Result<Self, Error>

Create from multiple 0-based ranges.

Note that the input ranges are 1-based inclusive, as used by git, and the output is a zero-based BlameRanges instance.

If the input vector is empty, the result will be WholeFile.

Source§

impl BlameRanges

Source

pub fn add_one_based_inclusive_range( &mut self, new_range: RangeInclusive<u32>, ) -> Result<(), Error>

Add a single range to blame.

The new range will be merged with any overlapping existing ranges.

Source

pub fn to_zero_based_exclusive_ranges(&self, max_lines: u32) -> Vec<Range<u32>>

Gets zero-based exclusive ranges.

Trait Implementations§

Source§

impl Clone for BlameRanges

Source§

fn clone(&self) -> BlameRanges

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for BlameRanges

Source§

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

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

impl Default for BlameRanges

Source§

fn default() -> BlameRanges

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

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.