rwconfig
Read config files, change values with get/set, then write everything back in one go with save(). Like getters and setters with dirty-tracking.
Features
- Get/set by path — Use dot paths (
"info.a","a.b.c") to read and write nested values. - Dirty tracking — Every
set()marks the config dirty;save()writes only when needed. - Multiple formats — JSON, JSON5, JSONC, YAML, TOML; format is inferred from the file extension.
Installation
Usage
use ;
use json;
Supported formats
| Extension | Format |
|---|---|
.json, .json5, .jsonc |
JSON |
.yaml, .yml |
YAML |
.toml |
TOML |
API overview
| Item | Description |
|---|---|
RWConfig::from_file(path) |
Load config from a file. |
cfg.get(path) |
Get a value by dot path → Option<&Value>. |
cfg.set(path, value) |
Set a value; creates parent keys if needed. |
cfg.is_dirty() |
Whether there are unsaved changes. |
cfg.save() |
Write changes to the file (no-op if not dirty). |
Error |
Io, Parse, Path variants. |
ConfigFormat |
Json, Yaml, Toml. |
get_path / set_path |
Work on a raw serde_json::Value by path. |
Contribution
- Clone this repository
- Install the latest Rust
- Run tests:
cargo test - Run the demo:
cargo run
License
Published under the MIT license. Made by @YONGQI 💛
🛠️ auto updated with automd-rs