facet-diff

Crates.iofacet-diff
lib.rsfacet-diff
version0.43.2
created_at2025-06-30 16:03:02.310464+00
updated_at2026-01-23 18:03:41.258502+00
descriptionStructural diffing for Facet types with human-readable output - no PartialEq required
homepagehttps://facet.rs
repositoryhttps://github.com/facet-rs/facet
max_upload_size
id1732047
size401,181
Amos Wenger (fasterthanlime)

documentation

README

facet-diff

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

facet-diff

Structural diffing for Facet types with human-readable output.

Overview

facet-diff computes differences between two values using reflection. It works on any type that implements Facet, without requiring manual diff implementations or PartialEq.

use facet_diff::{FacetDiff, format_diff};

let old = MyStruct { name: "alice", count: 1 };
let new = MyStruct { name: "alice", count: 2 };

let diff = old.diff(&new);
println!("{}", format_diff(&diff));
// Shows: count: 1 → 2

Features

  • Reflection-based: Works on any Facet type automatically
  • Human-readable output: Multiple output formats (colored, plain, compact)
  • Sequence diffing: Uses Myers' algorithm for optimal sequence alignment
  • Float tolerance: Configure epsilon for floating-point comparisons

Usage

Basic Diffing

use facet_diff::FacetDiff;

let diff = old_value.diff(&new_value);

if diff.is_equal() {
    println!("Values are equal");
} else {
    println!("Changes detected");
}

Formatted Output

use facet_diff::{format_diff, format_diff_compact};

// Full colored diff
let output = format_diff(&diff);

// Compact single-line format
let compact = format_diff_compact(&diff);

With Options

use facet_diff::{DiffOptions, diff_new_peek_with_options};
use facet_reflect::Peek;

let options = DiffOptions::new()
    .with_float_tolerance(0.001);

let diff = diff_new_peek_with_options(
    Peek::new(&old),
    Peek::new(&new),
    &options,
);

Architecture

facet-diff uses facet-reflect to traverse values structurally:

  1. Peek - facet's reflection API provides access to fields and values
  2. Myers' algorithm - Optimal diff for sequences (lists, arrays)
  3. Recursive comparison - Fields compared by structure, not equality
  4. Layout rendering - facet-diff-core handles output formatting

Related Crates

  • facet-diff-core: Core diff types and rendering
  • facet-reflect: Reflection API for traversing Facet values
  • facet-pretty: Pretty-printing for Facet values

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