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.
DeleteToEnd
Remove the lines from low through the end of the file, inclusive.
Replace
Replace the lines from low through high, inclusive, with the lines in ‘lines’.
Fields
Insert
Insert the provided ‘lines’ after the line with index ‘pos’.
Implementations§
Source§impl<'a> DiffCommand<'a>
impl<'a> DiffCommand<'a>
Sourcepub(crate) fn apply_to(&self, target: &mut DiffResult<'a>) -> Result<(), Error>
pub(crate) fn apply_to(&self, target: &mut DiffResult<'a>) -> Result<(), Error>
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.
Sourcepub(crate) fn apply_transformation(
&self,
input: &mut DiffResult<'a>,
output: &mut DiffResult<'a>,
) -> Result<(), Error>
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.
Sourcepub(crate) fn lines(&self) -> Option<&[&'a str]>
pub(crate) fn lines(&self) -> Option<&[&'a str]>
Return the lines that we should add to the output
Sourcepub(crate) fn linebuf_mut(&mut self) -> Option<&mut Vec<&'a str>>
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.
Sourcepub(crate) fn following_lines(&self) -> Option<usize>
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.
Sourcepub(crate) fn first_removed_line(&self) -> usize
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.
Trait Implementations§
Source§impl<'a> Clone for DiffCommand<'a>
impl<'a> Clone for DiffCommand<'a>
Source§fn clone(&self) -> DiffCommand<'a>
fn clone(&self) -> DiffCommand<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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> UnsafeUnpin for DiffCommand<'a>
impl<'a> UnwindSafe for DiffCommand<'a>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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