#initial #default #directories #config #heirarchical

figgy

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

3 releases

0.1.2 May 17, 2023
0.1.1 May 17, 2023
0.1.0 May 17, 2023

#2235 in Parser implementations

42 downloads per month

MIT license

9KB
163 lines

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();

Dependencies

~0.7–1.6MB
~35K SLoC