Expand description
Semantic diffing for Rust structs.
diffo computes structural differences between two values of the same type,
leveraging serde for serialization. No derive macros needed - just implement
Serialize and you’re ready to go.
§Examples
Basic usage:
use diffo::diff;
use serde::Serialize;
#[derive(Serialize)]
struct User {
id: u64,
name: String,
}
let old = User { id: 1, name: "Alice".into() };
let new = User { id: 1, name: "Bob".into() };
let d = diff(&old, &new).unwrap();
assert!(!d.is_empty());With configuration:
use diffo::{diff_with, DiffConfig};
let config = DiffConfig::new()
.mask("password");
let d = diff_with(&old, &new, &config).unwrap();§Output Formats
Diff::to_pretty: Human-readable colored outputDiff::to_json: JSON representationDiff::to_json_patch: RFC 6902 JSON PatchDiff::to_markdown: Markdown table
§Performance
Complexity is O(n) for most operations, where n is the number of fields. Sequence diffing is index-based (O(n)), not LCS-based (O(n²)).
Modules§
- format
- Output formatters for diffs.
Structs§
- Diff
- Represents a complete diff between two values.
- Diff
Config - Configuration for diff computation.
- Path
- Represents a path to a field in a nested structure.
Enums§
- Change
- Represents a change at a specific path in the diff.
- Error
- Error type for diff operations.
- Format
Error - Error type for formatting operations.
- Sequence
Diff Algorithm - Algorithm to use for sequence diffing.
Traits§
- Value
Ext - Extension trait for Value to provide convenient accessor methods.
Functions§
- apply
- Apply a diff to a base value, producing a new value with changes applied.
- diff
- Compute diff between two values of the same type.
- diff_
with - Compute diff with custom configuration.
Type Aliases§
- Comparator
- Type alias for custom comparator functions.