figcon
A stupid-simple synchronous serde_json config file manager
I made this package for extremely basic json configuration for development or small applications, optimizing for simplicity/functionality over performance or quality. Feel free to never use this crate if you so please.
It is by no means a proper or efficient config manager, nor a database.
Key/Value pairs work fine with any serde_json::Value type.
If you wish to make object trees or categories, this library extends the Value implementation to allow some primitive object tree manipulation. See the examples below.
Use Example
use std::{env, path::Path};
use figcon::{FigCon, ValueExtensions};
use serde_json::json;
fn main() {
let mut conf = FigCon::load_or_default(
Path::join(env::current_dir().unwrap().as_path(), "config.json")
);
conf.set_key_st("Static String Key", json!("Static Value Type"));
conf.set_key("Dynamic String Key".to_owned(), json!(1234));
conf.get_key_st("Static String Key");
conf.get_key("Dynamic String Key".to_owned());
conf.has_key_st("Another String");
conf.remove_key_st("Another String");
conf.has_key_st("Another String");
let parent = conf.new_obj_st("Subtree One"); let child = parent.new_obj_st("child").unwrap();
child.set_key_st("Child's parameter", json!(1234));
let subchild = child.new_obj_st("Child's Subtree").unwrap();
subchild.set_key_st("Subchild's parameter", json!("hello world!"));
let nsub = conf.get_obj_st("Subtree One").unwrap();
nsub.has_key_st("Child's parameter");
conf.save();
}
Output of the example above (./config.json)
{
"Dynamic String Key": 1234,
"Static String Key": "Static Value Type",
"Subtree One": {
"child": {
"Child's Subtree": {
"Subchild's parameter": "hello world!"
},
"Child's parameter": 1234
}
}
}