1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#[macro_use]
extern crate failure;

extern crate serde;
extern crate serde_derive;
extern crate serde_json;

mod config;

use failure::Error;
use serde_json::Value;

pub type Result<T> = ::std::result::Result<T, Error>;

/// save Json to local
/// value: Json to save.
/// path: local path where to save, `empty` will save to default path `./settings.json`
pub fn config_save_settings(value: &Value, path: &str) -> Result<()> {
    config::save_settings(value, path)
}

/// get Json from local
/// path: Json file local path, `empty` will use default path `./settings.json`
pub fn config_get_settings(path: &str) -> Result<Value> {
    config::get_settings(path)
}

#[test]
fn example() -> Result<()> {
    let people = serde_json::json!({"name":"alice","age":18,"sex":true});
    let path = "./config_test.json";
    config_save_settings(&people, path)?;
    assert_eq!(people, config_get_settings(path)?);
    Ok(())
}