merge-struct

Crates.iomerge-struct
lib.rsmerge-struct
version0.1.0
sourcesrc
created_at2022-08-08 15:33:27.351677
updated_at2022-08-08 15:33:27.351677
descriptionDeep merge for serializable structs
homepage
repositoryhttps://github.com/jondot/merge-struct
max_upload_size
id640888
size9,992
Dotan J. Nahum (jondot)

documentation

https://docs.rs/merge-struct

README

Merge Struct

github crates.io docs.rs build status

This is a Rust library deep merges two serializable structs.

Dependency

[dependencies]
merge-struct = "0.1.0"

For most recent version see crates.io

Usage

use std::collections::BTreeMap;
use serde_json;
use serde::{Deserialize, Serialize};
use merge_struct::merge;

let left: Data = serde_json::from_str(
    r###"
{
    "is_root": false,
    "entries": {
        "/var/log/f2": {
            "name":"f2",
            "size": 5
        }
    },
    "folders": [
        {
            "name": "/var/log",
            "num_files": 20
        }
    ]
}
"###,
)
.unwrap();

let right: Data = serde_json::from_str(
    r###"
{
    "folders":[],
    "entries": {
        "/var/log/f1": {
            "name":"f1",
            "size": 12
        }
    }
}
"###,
).unwrap();

let res = merge(&left, &right);

Copyright

Copyright (c) 2022 @jondot. See LICENSE for further details.

Commit count: 3

cargo fmt