use cool_diff::{
ArrayMatchConfig, ArrayMatchMode, DiffConfig, DiffRenderer as _, MatchConfig, YamlRenderer,
};
fn main() {
let actual = serde_json::json!({
"project": "cool-diff",
"steps": ["build", "test", "deploy"],
"tags": ["rust", "diff", "yaml"],
"contributors": [
{"email": "alice@example.com", "role": "maintainer"},
{"email": "bob@example.com", "role": "contributor"},
],
});
let expected = serde_json::json!({
"project": "cool-diff",
"steps": ["build", "lint", "deploy"],
"tags": ["yaml"],
"contributors": [
{"email": "bob@example.com", "role": "reviewer"},
],
});
let config = DiffConfig::new().with_match_config(
MatchConfig::new()
.with_config_at("steps", ArrayMatchConfig::new(ArrayMatchMode::Index))
.with_config_at("tags", ArrayMatchConfig::new(ArrayMatchMode::Contains))
.with_config_at(
"contributors",
ArrayMatchConfig::new(ArrayMatchMode::Key("email".to_owned())),
),
);
let tree = cool_diff::diff(&actual, &expected, &config).unwrap();
let output = YamlRenderer::new().render(&tree);
print!("{output}");
}