| Crates.io | zconf |
| lib.rs | zconf |
| version | 0.1.4-rc.2 |
| created_at | 2024-12-02 19:59:05.673179+00 |
| updated_at | 2025-07-18 05:51:04.365977+00 |
| description | help to write configuration files |
| homepage | |
| repository | https://github.com/wiiznokes/zconf |
| max_upload_size | |
| id | 1469144 |
| size | 32,000 |
Manage configuration files
The basic idea is to provide a safe abscraction arround updating and accessing your settings. You should not be allowed to change the config struct without writting on the filesystem (unless you want to).
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use zconf::ConfigManager;
#[derive(Debug, Serialize, Deserialize, Default)]
struct Settings {
name: String,
value: i32,
}
fn main() {
let path = PathBuf::from("settings.toml");
let mut config_manager = ConfigManager::<Settings, zconf::Toml>::new(&path);
config_manager.update(|settings| {
settings.name = "Example".to_string();
settings.value = 42;
});
println!("Current settings: {:?}", config_manager.data());
}
In general, you will want to use a crate like directories to get the path of the system config directory.
toml and json are integrated with feature flag, toml being the default one. You can also provide a custom format.)