Module similar::udiff

source ·
Expand description

This module provides unified diff functionality.

It is available for as long as the text feature is enabled which is enabled by default:

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 the Display implementation or UnifiedDiff or UnifiedDiff::to_writer.

The former uses DiffableStr::to_string_lossy, the latter uses DiffableStr::as_bytes for each line.

Structs

Unified diff formatter.
Unified diff hunk formatter.
Unified diff hunk header formatter.

Functions

Quick way to get a unified diff as string.