figgy

Crates.iofiggy
lib.rsfiggy
version0.1.2
sourcesrc
created_at2023-05-17 03:47:45.310546
updated_at2023-05-17 03:58:29.880003
descriptionA small library for managing config files which supports heirarchical directories, defaults, and writing initial files
homepage
repositoryhttps://github.com/DanielCoulbourne/figgy
max_upload_size
id866564
size8,729
Daniel Coulbourne (DanielCoulbourne)

documentation

README

figgy

A small Rust library for managing config files which supports heirarchical directories, defaults, and writing initial files

Example:

~/.config/myapp/myapp.config.json OR ~/.myapp/myapp.config.json

{
    "api_key": "1234abcdef!@#$%",
    "api_version": 3
}

Your Rust program:

    use serde::{Deserialize, Serialize};

    #[derive(Serialize, Deserialize)]
    struct ApiKeysConfig {
        api_key: String,
        api_version: i16,
    }

    let config = ConfigFile::<ApiKeysConfig>::new("myapp.config.json")
            .directory("~/.config/myapp/")
            .directory("~/.myapp/")
            .read();

Default Configs

If you want a default configuration, you can set one with .default(). If you want to automatically write a config file if none is detected, use .create_file_if_not_found()

let config = ConfigFile::<PersonConfig>::new("myapp.config.json")))
            .directory("~/.config/myapp/")
            .directory("~/.myapp/")
            .create_file_if_not_found()
            .default(ApiKeysConfig {
                api_key: "Super secret API key",
                api_version: 25,
            })
            .read();
Commit count: 8

cargo fmt