Skip to main content

Module patch

Module patch 

Source
Expand description

JSON Patch utilities for AG-UI state delta generation.

This module provides utilities for working with JSON Patch (RFC 6902) operations, enabling efficient state synchronization between agents and frontends through delta updates.

§Overview

JSON Patch is a format for describing changes to a JSON document. Instead of sending the entire state on every update, you can send just the changes (patches) which is more efficient for large state objects.

§Example

use ag_ui_core::patch::{create_patch, apply_patch};
use serde_json::json;

// Create a patch from two states
let old_state = json!({"count": 0, "items": []});
let new_state = json!({"count": 1, "items": ["apple"]});

let patch = create_patch(&old_state, &new_state);

// Apply patch to recreate the new state
let mut state = old_state.clone();
apply_patch(&mut state, &patch).unwrap();
assert_eq!(state, new_state);

Structs§

AddOperation
JSON Patch ‘add’ operation representation
CopyOperation
JSON Patch ‘copy’ operation representation
MoveOperation
JSON Patch ‘move’ operation representation
Patch
Representation of JSON Patch (list of patch operations)
PatchBuilder
A builder for constructing JSON Patches programmatically.
PatchError
Error type for patch operations.
RemoveOperation
JSON Patch ‘remove’ operation representation
ReplaceOperation
JSON Patch ‘replace’ operation representation
TestOperation
JSON Patch ‘test’ operation representation

Enums§

PatchOperation
JSON Patch single patch operation

Functions§

apply_patch
Applies a JSON Patch to a JSON value in place.
apply_patch_from_value
Applies a JSON Patch from a JSON array representation.
can_apply_patch
Checks if applying a patch would succeed without actually modifying the target.
create_patch
Creates a JSON Patch representing the difference between two JSON values.
merge_patches
Merges two patches into one.
patch_to_value
Converts a Patch to a JSON value for serialization.
patch_to_vec
Converts a Patch to a vector of JSON values.