gliff/types

Shared type definitions for the gliff diffing library.

Import this module to access all types used in gliff’s public API.

Types

The diff algorithm to use.

pub type Algorithm {
  Myers
  Patience
}

Constructors

  • Myers

    Myers O(ND) algorithm — optimal edit distance, fast for similar texts.

  • Patience

    Patience algorithm — anchors on unique lines for more readable output.

Post-processing cleanup mode to apply after diffing.

pub type Cleanup {
  NoCleanup
  SemanticCleanup
  SemanticLosslessCleanup
}

Constructors

  • NoCleanup

    No cleanup — return the raw diff result.

  • SemanticCleanup

    Eliminate trivial equalities and merge adjacent edits.

  • SemanticLosslessCleanup

    Shift edit boundaries to natural positions (word, sentence, line boundaries).

Configuration for diff operations.

pub type DiffConfig {
  DiffConfig(
    algorithm: Algorithm,
    cleanup: Cleanup,
    max_iterations: Int,
  )
}

Constructors

  • DiffConfig(
      algorithm: Algorithm,
      cleanup: Cleanup,
      max_iterations: Int,
    )

    Arguments

    algorithm

    Which algorithm to use.

    cleanup

    Post-processing cleanup mode.

    max_iterations

    Maximum iterations before fallback. 0 means unlimited.

The result of a configurable diff operation.

pub type DiffResult {
  Complete(edits: List(Edit))
  Truncated(edits: List(Edit))
}

Constructors

  • Complete(edits: List(Edit))

    The diff completed within the iteration budget.

  • Truncated(edits: List(Edit))

    The iteration budget was exceeded; result is a valid but approximate diff.

A grouped edit operation representing one or more contiguous lines (or tokens) that share the same change type.

pub type Edit {
  Equal(lines: List(String))
  Insert(lines: List(String))
  Delete(lines: List(String))
}

Constructors

  • Equal(lines: List(String))

    Lines present in both old and new text.

  • Insert(lines: List(String))

    Lines added in the new text.

  • Delete(lines: List(String))

    Lines removed from the old text.

A hunk in unified diff format, representing a localized group of changes with surrounding context lines.

pub type Hunk {
  Hunk(
    old_start: Int,
    old_count: Int,
    new_start: Int,
    new_count: Int,
    edits: List(Edit),
  )
}

Constructors

  • Hunk(
      old_start: Int,
      old_count: Int,
      new_start: Int,
      new_count: Int,
      edits: List(Edit),
    )

    Arguments

    old_start

    1-indexed starting line in the old file.

    old_count

    Number of lines from the old file in this hunk.

    new_start

    1-indexed starting line in the new file.

    new_count

    Number of lines from the new file in this hunk.

    edits

    The edit operations within this hunk.

An edit enriched with character-level highlighting information.

pub type InlineEdit {
  InlineEqual(lines: List(String))
  InlineDelete(spans: List(Span))
  InlineInsert(spans: List(Span))
}

Constructors

  • InlineEqual(lines: List(String))

    A line that is unchanged between old and new.

  • InlineDelete(spans: List(Span))

    A deleted line with spans showing which characters were removed.

  • InlineInsert(spans: List(Span))

    An inserted line with spans showing which characters were added.

A single-element edit produced by the diff algorithm internally. Grouped into Edit before being returned to users.

pub type RawEdit {
  RawEqual(value: String)
  RawInsert(value: String)
  RawDelete(value: String)
}

Constructors

  • RawEqual(value: String)
  • RawInsert(value: String)
  • RawDelete(value: String)

A segment within a line for inline change highlighting.

pub type Span {
  Unchanged(text: String)
  Changed(text: String)
}

Constructors

  • Unchanged(text: String)

    Text that is the same in both old and new.

  • Changed(text: String)

    Text that differs between old and new.

Search Document