Skip to main content

Crate loom_diff

Crate loom_diff 

Source
Expand description

§loom-diff

Line-level diff used by both the loom CLI and the loom-gateway. Pure functions: feed in two text blobs (or byte slices), get back either a structured FileDiff (good for JSON / UI consumers) or a String of git-style unified diff (good for terminal output).

Backed by the similar crate’s Myers algorithm. Binary blobs are detected via a simple null-byte heuristic and surface as a Binary diff variant — we don’t try to render diffs of binary content.

§Layering

loom-web · loom-gateway   ← consumers
loom-diff                 ← THIS CRATE
─── frozen below ─────────────────────────
weave-sdk · Strand · Locus · Lens · DHT · Forum

Structs§

DiffHunk
A contiguous run of changes plus surrounding context.
DiffLine
One line in a hunk.
FileDiff
A diff for a single path. The shape carries enough information to render git-style unified output, group changes per-hunk in a UI, and surface summary stats.
UnifiedDiffOptions
Options for unified_diff_string.

Enums§

BinaryReason
Why a diff couldn’t be rendered as text.
DiffError
Errors produced by loom-diff.
DiffLineKind
Per-line tag — additions, deletions, unchanged context lines, plus the two structural markers around a hunk gap.
FileDiffStatus
File-level status.

Functions§

diff_blobs
Build a FileDiff from two byte slices. Detects binary content (null-byte heuristic, then utf-8 check) and surfaces it as a Binary status without trying to render lines.
file_diff
Convenience: diff two text strings, treating absent strings as empty (file added/deleted). Provided for tests and for callers that already hold UTF-8 strings.
looks_binary
Heuristic: a byte slice is “probably binary” if the first 8KB contains a null byte. This is the same check git uses.
unified_diff_string
Render a FileDiff as a unified-diff string. Identical layout to git diff so agents and humans both find this reading exactly as they expect. Empty string for unchanged files.

Type Aliases§

Result
Result alias.