Struct similar::udiff::UnifiedDiff

source ·
pub struct UnifiedDiff<'diff, 'old, 'new, 'bufs, T: DiffableStr + ?Sized> { /* private fields */ }
Expand description

Unified diff formatter.

use similar::TextDiff;
let text_diff = TextDiff::from_lines(old_text, new_text);
print!("{}", text_diff
    .unified_diff()
    .context_radius(10)
    .header("old_file", "new_file"));

Unicode vs Bytes

The UnifiedDiff type supports both unicode and byte diffs for all types compatible with DiffableStr. You can pick between the two versions by using [UnifiedDiff.to_string] or [UnifiedDiff.to_writer]. The former uses DiffableStr::to_string_lossy, the latter uses DiffableStr::as_bytes for each line.

Implementations§

Creates a formatter from a text diff object.

Changes the context radius.

The context radius is the number of lines between changes that should be emitted. This defaults to 3.

Sets a header to the diff.

a and b are the file names that are added to the top of the unified file format. The names are accepted verbatim which lets you encode a timestamp into it when separated by a tab (\t). For more information see the unified diff format specification

Controls the missing newline hint.

By default a special \ No newline at end of file marker is added to the output when a file is not terminated with a final newline. This can be disabled with this flag.

Iterates over all hunks as configured.

Write the unified diff as bytes to the output stream.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.