Skip to main content

fionn_diff/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! # JSON Diff/Patch/Merge
3//!
4//! High-performance JSON structural operations with SIMD acceleration.
5//!
6//! This module provides three related capabilities:
7//!
8//! ## JSON Diff
9//! Generate a list of operations that transform one JSON document into another.
10//! Follows the spirit of RFC 6902 (JSON Patch) for the output format.
11//!
12//! ## JSON Patch (RFC 6902)
13//! Apply a sequence of operations to a JSON document:
14//! - `add`: Insert a value at a path
15//! - `remove`: Delete a value at a path
16//! - `replace`: Replace a value at a path
17//! - `move`: Move a value from one path to another
18//! - `copy`: Copy a value from one path to another
19//! - `test`: Verify a value equals the expected value
20//!
21//! ## JSON Merge Patch (RFC 7396)
22//! A simpler merge format where:
23//! - Objects are recursively merged
24//! - `null` values indicate deletion
25//! - Other values replace existing ones
26//!
27//! ## Performance
28//!
29//! Uses SIMD acceleration for:
30//! - Bulk string comparison (detect unchanged strings quickly)
31//! - Array element comparison
32//! - Finding longest common subsequence in arrays
33
34mod compute;
35mod csv_diff;
36mod diff_tape;
37mod diff_zerocopy;
38mod merge;
39mod patch;
40mod simd_compare;
41mod tape_merge;
42mod tape_patch;
43
44pub use compute::{DiffOptions, json_diff, json_diff_with_options};
45pub use csv_diff::{
46    CellChange, CsvDiff, CsvDiffOp, CsvDiffOptions, CsvDiffStats, RowIdentityMode, csv_diff,
47    csv_diff_tapes,
48};
49pub use diff_tape::{
50    TapeDiff, TapeDiffOp, TapeDiffOptions, TapeValueOwned, diff_tapes, diff_tapes_with_options,
51};
52pub use diff_zerocopy::{JsonPatchRef, PatchOperationRef, json_diff_zerocopy};
53pub use merge::{deep_merge, json_merge_patch, merge_many, merge_patch_to_value};
54pub use patch::{JsonPatch, PatchError, PatchOperation, apply_patch, apply_patch_mut};
55pub use simd_compare::{
56    json_numbers_equal, json_strings_equal, simd_bytes_equal, simd_find_first_difference,
57};
58pub use tape_merge::{
59    StreamingMergeOptions, deep_merge_tape_into_value, deep_merge_tapes, merge_many_tapes,
60    merge_tape_into_value, merge_tapes, streaming_merge,
61};
62#[cfg(feature = "toml")]
63pub use tape_patch::value_to_toml;
64#[cfg(feature = "yaml")]
65pub use tape_patch::value_to_yaml;
66pub use tape_patch::{
67    apply_tape_diff, patch_tape, tape_to_value, three_way_patch, value_to_json,
68    value_to_json_pretty,
69};
70
71// Re-export generic (format-agnostic) diff/patch types and functions from fionn-core
72pub use fionn_core::diffable::{
73    DiffOptions as GenericDiffOptions, DiffValueKind, DiffableValue, GenericPatch,
74    GenericPatchOperation, compute_diff as generic_compute_diff,
75    compute_diff_with_options as generic_compute_diff_with_options,
76};
77pub use fionn_core::patchable::{
78    PatchError as GenericPatchError, Patchable, apply_operation as generic_apply_operation,
79    apply_patch as generic_apply_patch,
80};