Skip to main content

can_apply_patch

Function can_apply_patch 

Source
pub fn can_apply_patch(target: &Value, patch: &Patch) -> bool
Expand description

Checks if applying a patch would succeed without actually modifying the target.

This is useful for validation before committing to a patch operation.

ยงExample

use ag_ui_core::patch::{can_apply_patch, PatchBuilder};
use serde_json::json;

let state = json!({"count": 0});
let valid_patch = PatchBuilder::new().replace("/count", json!(1)).build();
let invalid_patch = PatchBuilder::new().remove("/nonexistent").build();

assert!(can_apply_patch(&state, &valid_patch));
assert!(!can_apply_patch(&state, &invalid_patch));