Is there exists a Config Management crate?

Prerequite

so i am building a tauri desktop application that needs to persist the app config on disk that is managed by the app and user may edit it

Problem

right now, i am having to mannualy deal with the saving, reading mirating confi file using serde and serde_json. and after encountring a plathera of bugs, i decided there must be something in the rust ecosystem that solves this problem

so i just wanted to ask you gyuz for a solution that allows me to :

  • save/read config file form disk
  • handle bad schema config files
  • handles constantly evolving config schema

Note that this is all achievable with serde, serde_json and your configuration being represented by appropriate types. For example:

use serde::Deserialize;

#[derive(Deserialize)]
struct Config {
    username: String,
    // ...
}

fn main() {
    let json = r#"{
        "username": "Tom"
    }"#;
    
    let config: Config = serde_json::from_str(json).unwrap();
    
    println!("Hello {}!", &config.username);
}

Playground.

I'd take a look at figment. Started using it recently, liking it so far. Out of the box it handles layered reading (defaults + file + env) and gives proper errors like key window.width in config.toml instead of raw serde output, which really helps when fields are missing or malformed. I'm only using the basics myself, but the crate is extensible - there are third-party Provider`s out there (like this one), and you can write your own if nothing fits.

It doesn't handle writing to disk (that's still plain serde), and schema migrations are on you - but paired with a versioned enum via #[serde(tag = "version")] it works fine.