pub struct Diff {
pub lines: Vec<DiffLine>,
pub hunks: Vec<Hunk>,
pub json: bool,
pub note: Option<String>,
}Expand description
The diff of two texts: every line, and the hunks over them.
Fields§
§lines: Vec<DiffLine>Every line of both texts in order: unchanged, removed and added (and, for JSON, summary) lines.
hunks: Vec<Hunk>The changes with their context, in order. Lines outside every hunk are unchanged
(Diff::gaps).
json: boolCompared as JSON (Diff::json).
note: Option<String>Why a JSON comparison fell back to text (a side did not parse).
Implementations§
Source§impl Diff
impl Diff
Sourcepub fn text(old: &str, new: &str, context: usize) -> Diff
pub fn text(old: &str, new: &str, context: usize) -> Diff
The line diff of old and new, with context unchanged lines around each change.
Sourcepub fn json(old: &str, new: &str, context: usize, array_summary: usize) -> Diff
pub fn json(old: &str, new: &str, context: usize, array_summary: usize) -> Diff
The diff of two JSON documents compared by key (Diff::json_values); when a side does
not parse, the text diff with a Diff::note saying why.
Sourcepub fn json_values(
old: &Value,
new: &Value,
context: usize,
array_summary: usize,
) -> Diff
pub fn json_values( old: &Value, new: &Value, context: usize, array_summary: usize, ) -> Diff
The diff of two JSON values: both printed with sorted keys (two-space indent), arrays
longer than array_summary as one line each, then compared line by line. A changed long
array becomes one LineKind::Summary line. Trailing commas are not compared, so adding
a key at the end does not mark the line before it as changed.
Sourcepub fn removed(&self) -> usize
pub fn removed(&self) -> usize
Lines removed (summary lines count as one added and one removed).
Sourcepub fn gaps(&self) -> Vec<Range<usize>>
pub fn gaps(&self) -> Vec<Range<usize>>
The unchanged runs outside the hunks, as ranges of Diff::lines: before the first hunk,
between hunks and after the last (empty runs left out). gaps()[i] comes before
hunks[i] when it ends where that hunk starts.
Trait Implementations§
impl Eq for Diff
impl StructuralPartialEq for Diff
Auto Trait Implementations§
impl Forget for Diff
impl Freeze for Diff
impl Move for Diff
impl RefUnwindSafe for Diff
impl Send for Diff
impl Sync for Diff
impl Unpin for Diff
impl UnsafeUnpin for Diff
impl UnwindSafe for Diff
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreSource§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
Source§type NoneType = T
type NoneType = T
NoneValue::null_value produces.Source§fn null_value() -> T
fn null_value() -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().