#json-path #relative-path #data #file-path #load #serializable #loader

serde-loader

Serde wrapper to load/save serializable data from relative paths

6 releases

0.2.0 Jul 26, 2023
0.1.4 Apr 5, 2022
0.1.3 Feb 23, 2022

#673 in Encoding

Download history 1/week @ 2024-02-20 4/week @ 2024-02-27 1/week @ 2024-03-05 70/week @ 2024-03-12

76 downloads per month

MIT license

23KB
753 lines

serde-loader

[ crates.io | docs.rs ]

It provides serde wrapper to load/save serializable data from relative paths.

Example

It allows to write file paths instead of data during serialization. Suppose we have the following JSON files to be loaded.

main.json

{
    "sub": "sub/sub.json"
}

sub/sub.json

{
    "sub": "sub/sub.json"
}

sub/sub/sub_of_sub.json

{
    "sub": "sub/sub_of_sub.json"
}

This crate provides the JsonPath wrapper load JSON files recursively.

use serde_loader::JsonPath;
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct Main {
    pub sub: JsonPath<Sub>
}


#[derive(Serialize, Deserialize)]
struct Sub {
    pub sub: JsonPath<SubOfSub>
}


#[derive(Serialize, Deserialize)]
struct SubOfSub {
    pub name: String,
    pub value: String,
}

let config: JsonPath<Main> = JsonPath::open("tests/config-example/main.json")?;
config.save()?;

License

MIT license. See the license file.

Dependencies

~1.3–2.6MB
~57K SLoC