Enum DiffCommand

Source
pub(crate) enum DiffCommand<'a> {
    Delete {
        low: usize,
        high: usize,
    },
    DeleteToEnd {
        low: usize,
    },
    Replace {
        low: usize,
        high: usize,
        lines: Vec<&'a str>,
    },
    Insert {
        pos: usize,
        lines: Vec<&'a str>,
    },
}
Expand description

A command that can appear in a diff. Each command tells us to remove zero or more lines, and insert zero or more lines in their place.

Commands refer to lines by 1-indexed line number.

Variants§

§

Delete

Remove the lines from low through high, inclusive.

Fields

§low: usize

The first line to remove

§high: usize

The last line to remove

§

DeleteToEnd

Remove the lines from low through the end of the file, inclusive.

Fields

§low: usize

The first line to remove

§

Replace

Replace the lines from low through high, inclusive, with the lines in ‘lines’.

Fields

§low: usize

The first line to replace

§high: usize

The last line to replace

§lines: Vec<&'a str>

The text to insert instead

§

Insert

Insert the provided ‘lines’ after the line with index ‘pos’.

Fields

§pos: usize

The position after which to insert the text

§lines: Vec<&'a str>

The text to insert

Implementations§

Source§

impl<'a> DiffCommand<'a>

Source

pub(crate) fn apply_to(&self, target: &mut DiffResult<'a>) -> Result<(), Error>

Available on crate feature slow-diff-apply only.

Transform ‘target’ according to the this command.

Because DiffResult internally uses a vector of line, this implementation is potentially O(n) in the size of the input.

Source

pub(crate) fn apply_transformation( &self, input: &mut DiffResult<'a>, output: &mut DiffResult<'a>, ) -> Result<(), Error>

Apply this command to ‘input’, moving lines into ‘output’.

This is a more efficient algorithm, but it requires that the diff commands are sorted in reverse order by line number. (Fortunately, the Tor ed diff format guarantees this.)

Before calling this method, input and output must contain the results of having applied the previous command in the diff. (When no commands have been applied, input starts out as the original text, and output starts out empty.)

This method applies the command by copying unaffected lines from the end of input into output, adding any lines inserted by this command, and finally deleting any affected lines from input.

We build the output value in reverse order, and then put it back to normal before giving it to the user.

Source

pub(crate) fn lines(&self) -> Option<&[&'a str]>

Return the lines that we should add to the output

Source

pub(crate) fn linebuf_mut(&mut self) -> Option<&mut Vec<&'a str>>

Return a mutable reference to the vector of lines we should add to the output.

Source

pub(crate) fn following_lines(&self) -> Option<usize>

Return the (1-indexed) line number of the first line in the input that comes after this command, and is not affected by it.

We use this line number to know which lines we should copy.

Source

pub(crate) fn first_removed_line(&self) -> usize

Return the (1-indexed) line number of the first line that we should clear from the input when processing this command.

This can be the same as following_lines(), if we shouldn’t actually remove any lines.

Source

pub(crate) fn is_insert(&self) -> bool

Return true if this is an Insert command.

Source

pub(crate) fn from_line_iterator<I>(iter: &mut I) -> Result<Option<Self>, Error>
where I: Iterator<Item = &'a str>,

Extract a single command from a line iterator that yields lines of the diffs. Return None if we’re at the end of the iterator.

Trait Implementations§

Source§

impl<'a> Clone for DiffCommand<'a>

Source§

fn clone(&self) -> DiffCommand<'a>

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<'a> Debug for DiffCommand<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for DiffCommand<'a>

§

impl<'a> RefUnwindSafe for DiffCommand<'a>

§

impl<'a> Send for DiffCommand<'a>

§

impl<'a> Sync for DiffCommand<'a>

§

impl<'a> Unpin for DiffCommand<'a>

§

impl<'a> UnwindSafe for DiffCommand<'a>

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T