# 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.
```rust,ignore
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
```rust,ignore
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
```rust,ignore
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
```rust,ignore
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