Skip to main content

Crate cool_diff

Crate cool_diff 

Source
Expand description

Compact, context-preserving diffs of structured data.

cool-diff compares two serde_json::Value trees and produces a minimal, human-readable diff. It is format-agnostic at the core and ships with a YAML-style renderer (YamlRenderer) out of the box.

§Quick start

use cool_diff::{diff, DiffConfig, DiffRenderer as _, YamlRenderer};

let actual = serde_json::json!({
    "server": {
        "host": "0.0.0.0",
        "port": 8080,
        "tls": true,
    }
});
let expected = serde_json::json!({
    "server": {
        "port": 3000,
    }
});

let tree = diff(&actual, &expected, &DiffConfig::default()).unwrap();

if !tree.is_empty() {
    let output = YamlRenderer::new().render(&tree);
    print!("{output}");
}

§Array matching

By default, arrays are compared by position (index). You can configure per-path matching via MatchConfig:

See DiffConfig and ArrayMatchConfig for configuration options.

Re-exports§

pub use config::AmbiguousMatchStrategy;
pub use config::ArrayMatchConfig;
pub use config::ArrayMatchMode;
pub use config::DiffConfig;
pub use config::MatchConfig;
pub use diff::Error;
pub use diff::diff;
pub use model::ChildKind;
pub use model::DiffKind;
pub use model::DiffNode;
pub use model::DiffTree;
pub use model::PathSegment;
pub use render::DiffRenderer;
pub use render::yaml::YamlRenderer;

Modules§

config
Configuration types for the diff algorithm.
diff
Core diff algorithm.
model
Data model for diff results.
render
Rendering diff trees as human-readable output.