Weave documentation
Rust referenceloom-diff

loom-diff · structured

Source declarations, signatures and documentation for structured.

Source: sigil/weave/tools/loom-diff/src/structured.rs. SHA-256: bc300069d31e40aa258ef0b451dd6e71f4c944c09a5b2ce0e6b95f2307ffe921.

This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.

structured::BinaryReason

Why a diff couldn't be rendered as text.

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum BinaryReason {
    /// One side contains null bytes (heuristic: looks_binary).
    NullByte,
    /// Bytes did not decode as utf-8 cleanly.
    NotUtf8,
}

Source line: 11.

structured::DiffLineKind

Per-line tag — additions, deletions, unchanged context lines, plus the two structural markers around a hunk gap.

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DiffLineKind {
    /// Line in `a` only — rendered with `-`.
    Delete,
    /// Line in `b` only — rendered with `+`.
    Insert,
    /// Line present in both — rendered with ` `.
    Equal,
}

Source line: 22.

structured::DiffLine

One line in a hunk.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DiffLine {
/// Whether this is `+`, `-`, or context.

pub kind: DiffLineKind,
/// 1-based line number on the `a` side; `None` for inserts.

#[serde(skip_serializing_if = "Option::is_none")]
pub a_line: Option<u32>,
/// 1-based line number on the `b` side; `None` for deletes.

#[serde(skip_serializing_if = "Option::is_none")]
pub b_line: Option<u32>,
/// Line content WITHOUT the trailing newline (we re-add on render).

pub content: String
}

Source line: 33.

structured::DiffHunk

A contiguous run of changes plus surrounding context.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DiffHunk {
/// Starting line on the `a` side (1-based).

pub a_start: u32,
/// Number of `a` lines in this hunk.

pub a_count: u32,
/// Starting line on the `b` side (1-based).

pub b_start: u32,
/// Number of `b` lines in this hunk.

pub b_count: u32,
/// Lines of the hunk, in order.

pub lines: Vec<DiffLine>
}

Source line: 48.

structured::FileDiffStatus

File-level status.

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FileDiffStatus {
    /// The file is identical on both sides.
    Unchanged,
    /// File added (only present on `b`).
    Added,
    /// File deleted (only present on `a`).
    Deleted,
    /// File present on both sides with content changes.
    Modified,
    /// File present on both sides but binary; no line-diff produced.
    Binary {
        /// Why the rendering was skipped.
        reason: BinaryReason,
    },
}

Source line: 64.

structured::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.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FileDiff {
/// Path on the `a` side. May differ from `b_path` for renames; v1

/// always sets these equal.

pub a_path: Option<String>,
/// Path on the `b` side.

pub b_path: Option<String>,
/// File-level status.

pub status: FileDiffStatus,
/// Hunks; empty when `status` is `Unchanged`/`Binary`.

pub hunks: Vec<DiffHunk>,
/// Total `+` lines across all hunks.

pub additions: u32,
/// Total `-` lines across all hunks.

pub deletions: u32
}

Source line: 84.

structured::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.

pub fn diff_blobs(
    a: Option<&[u8]>,
    b: Option<&[u8]>,
    a_path: Option<&str>,
    b_path: Option<&str>,
    context_lines: usize,
) -> FileDiff;

Source line: 103.

structured::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.

pub fn file_diff(
    a: Option<&str>,
    b: Option<&str>,
    a_path: Option<&str>,
    b_path: Option<&str>,
    context_lines: usize,
) -> FileDiff;

Source line: 252.

On this page