cool_diff/lib.rs
1//! Compact, context-preserving diffs of structured data.
2//!
3//! `cool-diff` compares two [`serde_json::Value`] trees and produces a minimal,
4//! human-readable diff. It is format-agnostic at the core and ships with a
5//! YAML-style renderer ([`YamlRenderer`]) out of the box.
6//!
7//! # Quick start
8//!
9//! ```
10//! use cool_diff::{diff, DiffConfig, DiffRenderer as _, YamlRenderer};
11//!
12//! let actual = serde_json::json!({
13//! "server": {
14//! "host": "0.0.0.0",
15//! "port": 8080,
16//! "tls": true,
17//! }
18//! });
19//! let expected = serde_json::json!({
20//! "server": {
21//! "port": 3000,
22//! }
23//! });
24//!
25//! let tree = diff(&actual, &expected, &DiffConfig::default()).unwrap();
26//!
27//! if !tree.is_empty() {
28//! let output = YamlRenderer::new().render(&tree);
29//! print!("{output}");
30//! }
31//! ```
32//!
33//! # Array matching
34//!
35//! By default, arrays are compared by position (index). You can configure
36//! per-path matching via [`MatchConfig`]:
37//!
38//! - [`ArrayMatchMode::Index`] - match by position (default)
39//! - [`ArrayMatchMode::Key`] - match by a configured distinguished field
40//! - [`ArrayMatchMode::Contains`] - find a matching element anywhere
41//!
42//! See [`DiffConfig`] and [`ArrayMatchConfig`] for configuration options.
43
44#![deny(clippy::unwrap_used)]
45#![warn(missing_docs)]
46
47/// Configuration types for the diff algorithm.
48pub mod config;
49
50/// Core diff algorithm.
51pub mod diff;
52
53/// Data model for diff results.
54pub mod model;
55
56/// Rendering diff trees as human-readable output.
57pub mod render;
58
59pub use config::{
60 AmbiguousMatchStrategy, ArrayMatchConfig, ArrayMatchMode, DiffConfig, MatchConfig,
61};
62pub use diff::{Error, diff};
63pub use model::{ChildKind, DiffKind, DiffNode, DiffTree, PathSegment};
64pub use render::DiffRenderer;
65pub use render::yaml::YamlRenderer;
66#[cfg(feature = "color")]
67pub use render::yaml::ColorMode;