zconf

Crates.iozconf
lib.rszconf
version0.1.4-rc.2
created_at2024-12-02 19:59:05.673179+00
updated_at2025-07-18 05:51:04.365977+00
descriptionhelp to write configuration files
homepage
repositoryhttps://github.com/wiiznokes/zconf
max_upload_size
id1469144
size32,000
(wiiznokes)

documentation

README

zconf

crates.io docs.rs license

Manage configuration files

Usage

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.

Goal / Vision

  • No macros (not that macros are always wrong, but they provide poor ide support and longer compile time)
  • config are contained in one file
  • simple (for example, an api that log error directly)

Feature

  • Atomic file operation, using atomicwrites
  • Watcher, using notify, see the libcosmic example
  • Various format support (toml and json are integrated with feature flag, toml being the default one. You can also provide a custom format.)
Commit count: 7

cargo fmt