Diff

Struct Diff 

Source
pub struct Diff { /* private fields */ }
Expand description

Use DiffBuilder to build Diff first and run Diff::compare to get the difference between two JSON values.

Implementations§

Source§

impl Diff

Source

pub fn compare(self) -> Option<Difference>

Examples found in repository?
examples/simple_object_diff.rs (line 17)
1fn main() {
2    let obj1 = serde_json::json!({
3        "user": "John",
4        "age": 31
5    });
6
7    let obj2 = serde_json::json!({
8        "user": "John",
9        "age": 33
10    });
11
12    let diff = sjdiff::DiffBuilder::default()
13        .source(obj1)
14        .target(obj2)
15        .build()
16        .unwrap();
17    let diff = diff.compare();
18
19    serde_json::to_writer_pretty(std::io::stdout(), &diff).unwrap();
20}
More examples
Hide additional examples
examples/ignore_with_rhai_script.rs (line 44)
1fn main() {
2    let obj1 = serde_json::json!({
3            "users": [
4                {
5                    "name": "Joe",
6                    "age": 43,
7                },
8                {
9                    "name": "Ana",
10                    "age": 33,
11                    "animals": {
12                        "type": "dog"
13                    }
14                },
15            ]
16        });
17
18    let obj2 = serde_json::json!({
19            "users": [
20                {
21                    "name": "Joe",
22                    "age": 43,
23                },
24                {
25                    "name": "Ana",
26                    "age": 33,
27                    "animals": {
28                        "type": "cat"
29                    }
30                },
31            ]
32        });
33
34    let script = r#"
35        let res = target.value_by_path("users.[_].age", curr_path);
36        res == 33
37        "#;
38
39    let diff = sjdiff::DiffBuilder::default()
40        .source(obj1)
41        .target(obj2)
42        .ignore_path_with_condition("users.[_].animals.type", sjdiff::IgnorePathCondition::Rhai(script.to_string()))
43        .build();
44    let diff = diff.unwrap().compare();
45    print!("{:?}", diff);
46}

Trait Implementations§

Source§

impl Debug for Diff

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Diff

Source§

fn default() -> Diff

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Diff

§

impl RefUnwindSafe for Diff

§

impl Send for Diff

§

impl Sync for Diff

§

impl Unpin for Diff

§

impl UnwindSafe for Diff

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.