Crates.io | figgy |
lib.rs | figgy |
version | 0.1.2 |
source | src |
created_at | 2023-05-17 03:47:45.310546 |
updated_at | 2023-05-17 03:58:29.880003 |
description | A small library for managing config files which supports heirarchical directories, defaults, and writing initial files |
homepage | |
repository | https://github.com/DanielCoulbourne/figgy |
max_upload_size | |
id | 866564 |
size | 8,729 |
A small Rust library for managing config files which supports heirarchical directories, defaults, and writing initial files
~/.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();
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();