rwconfig 1.0.1

Read/write config files with get/set and dirty-tracking; save() writes all changes at once
Documentation

rwconfig

Crates.io Version Crates.io Total Downloads docs.rs GitHub commit activity GitHub Repo stars

Read config files, change values with get/set, then write everything back in one go with save(). Like getters and setters with dirty-tracking.

Full documentation →

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

cargo add rwconfig

Usage

use rwconfig::{RWConfig, Error};
use serde_json::json;

fn main() -> Result<(), Error> {
    let mut cfg = RWConfig::from_file("config.json")?;

    // get (read)
    let port = cfg.get("server.port").and_then(|v| v.as_i64()).unwrap_or(8080);

    // set (write) — marks config dirty
    cfg.set("server.port", json!(9090))?;
    cfg.set("server.host", json!("0.0.0.0"))?;

    // write all changes to disk
    cfg.save()?;
    Ok(())
}

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