#serde-json #json #serde

merge-struct

Deep merge for serializable structs

1 unstable release

0.1.0 Aug 8, 2022

#1058 in Encoding

Download history 290/week @ 2024-07-21 466/week @ 2024-07-28 221/week @ 2024-08-04 205/week @ 2024-08-11 241/week @ 2024-08-18 101/week @ 2024-08-25 179/week @ 2024-09-01 179/week @ 2024-09-08 246/week @ 2024-09-15 211/week @ 2024-09-22 180/week @ 2024-09-29 287/week @ 2024-10-06 125/week @ 2024-10-13 98/week @ 2024-10-20 136/week @ 2024-10-27 159/week @ 2024-11-03

539 downloads per month
Used in 5 crates

Apache-2.0

10KB
166 lines

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.

Dependencies

~0.5–1MB
~20K SLoC