facet-xml-diff

Crates.iofacet-xml-diff
lib.rsfacet-xml-diff
version0.43.1
created_at2026-01-22 16:54:16.105174+00
updated_at2026-01-23 08:53:22.449189+00
descriptionDiff-aware XML serialization for facet
homepagehttps://facet.rs
repositoryhttps://github.com/facet-rs/facet
max_upload_size
id2062164
size32,828
Amos Wenger (fasterthanlime)

documentation

README

facet-xml-diff

Coverage Status crates.io documentation MIT/Apache-2.0 licensed Discord

Diff-aware XML serialization—render structural diffs as readable XML.

Overview

This crate renders diffs between facet values as XML with visual diff markers. It shows what changed between two values in a format that's easy to read, with proper alignment, colored output, and collapsing of unchanged regions.

Example

use facet::Facet;
use facet_diff::tree_diff;

#[derive(Facet)]
struct Rect {
    fill: String,
    x: i32,
    y: i32,
}

let old = Rect { fill: "red".into(), x: 10, y: 20 };
let new = Rect { fill: "blue".into(), x: 10, y: 20 };

let xml = facet_xml_diff::diff_to_string(&old, &new)?;

Output:

<rect
← fill="red"
→ fill="blue"
  x="10" y="20"
/>

Features

  • Diff markers: / (or -/+) prefix lines to show old vs new values
  • Value-only coloring: Only the changed values are colored, not the whole line
  • Alignment: Attributes align properly for readability
  • Collapsing: Long runs of unchanged content are collapsed with ...
  • ANSI colors: Optional terminal colors for better visibility

Options

use facet_xml_diff::{DiffSerializeOptions, DiffSymbols, DiffTheme};

let options = DiffSerializeOptions {
    symbols: DiffSymbols::ascii(),  // Use -/+ instead of arrows
    theme: DiffTheme::default(),
    colors: true,
    indent: "  ",
    max_line_width: 80,
    collapse_threshold: 3,
    ..Default::default()
};

Use Cases

  • Debugging configuration changes
  • Displaying diffs in CLI tools
  • Generating human-readable change logs
  • Testing serialization by comparing expected vs actual output

Sponsors

Thanks to all individual sponsors:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.

Commit count: 3380

cargo fmt