17 releases (10 breaking)
Uses new Rust 2024
| 0.43.2 | Jan 23, 2026 |
|---|---|
| 0.42.0 | Jan 6, 2026 |
| 0.41.0 | Dec 31, 2025 |
| 0.28.0 | Jul 25, 2025 |
#987 in Development tools
194 downloads per month
Used in 2 crates
(via facet-assert)
2MB
37K
SLoC
facet-diff
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
Facettype 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:
- Peek - facet's reflection API provides access to fields and values
- Myers' algorithm - Optimal diff for sequences (lists, arrays)
- Recursive comparison - Fields compared by structure, not equality
- 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:
...along with corporate sponsors:
...without whom this work could not exist.
Special thanks
The facet logo was drawn by Misiasart.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~9–14MB
~177K SLoC