serde-loader

Crates.ioserde-loader
lib.rsserde-loader
version0.2.0
sourcesrc
created_at2022-02-23 05:13:48.441819
updated_at2023-07-26 18:59:36.106469
descriptionSerde wrapper to load/save serializable data from relative paths
homepagehttps://github.com/jerry73204/serde-loader
repositoryhttps://github.com/jerry73204/serde-loader.git
max_upload_size
id537647
size25,058
(jerry73204)

documentation

https://docs.rs/serde-loader/

README

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.

Commit count: 20

cargo fmt