jatch/
lib.rs

1#![deny(
2    unsafe_code,
3    missing_docs,
4    unstable_features,
5    unused_import_braces,
6    unused_qualifications,
7    trivial_casts,
8    trivial_numeric_casts,
9    missing_debug_implementations,
10    missing_copy_implementations,
11    clippy::perf,
12)]
13
14//! A crate to provide a fast, correct and safe implementation of JSON Patch ([RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902))
15//! 
16//! It can apply patches to JSON documents:
17//!
18//! ```rust
19//! # use jatch::{apply, Patch, Path};
20//! # use serde_json::json;
21//! let doc = json!({"hello": "world"});
22//! let patch = Patch::Add {
23//!     path: Path::new("/foo"),
24//!     value: json!("bar"),
25//! };
26//! assert_eq!(
27//!     apply(doc, vec![patch]).unwrap(), 
28//!     json!({
29//!         "hello": "world",
30//!         "foo": "bar",
31//!     })
32//! );
33//! ```
34//! It can also calculate the diffs between 2 JSONs:
35//! ```rust
36//! # use jatch::{diff, Patch, Path};
37//! # use serde_json::json;
38//! let patches = diff(
39//!   json!({"hello": "world"}),  
40//!   json!({"hello": "world", "foo": "bar"}),
41//! );
42//! assert_eq!(
43//!     patches[0], 
44//!     Patch::Add {
45//!       path: Path::new("/foo"),
46//!       value: json!("bar"),
47//!     }
48//! );
49//! ```
50mod errors;
51mod patch;
52mod path;
53mod diff;
54
55pub use errors::Error;
56pub use patch::{
57    apply::{apply_single, apply},
58    Patch,
59};
60pub use path::Path;
61pub use diff::diff;
62