#config-file #default-config #config-toml #config #locations #env-var #load

config-dirs

Load a config file by trying out default config file locations

2 unstable releases

0.2.0 Oct 27, 2024
0.1.0 Jun 16, 2024

#794 in Encoding

Download history 5/week @ 2024-10-14 120/week @ 2024-10-21 26/week @ 2024-10-28 14/week @ 2024-11-04

165 downloads per month

MIT/Apache

7KB
61 lines

config-dirs

Load a config file by trying out default config file locations:

  • {NAME_SCREAMING_SNAKE_CASE}_CONFIG envitonment variable
  • ~/.config/{name}/config.toml
  • /etc/{name}/config.toml
  • /usr/local/etc/{name}/config.toml
  • ~/Library/Preferences/{name}/config.toml
  • /usr/local/etc/{name}/config.toml
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
struct Config {}

let config: Config = config_dirs::load("my-app", toml::from_str).expect("Failed to load config");

The case conversion of name for the environment variable is done using convert_case::Case::ScreamingSnake.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in config-dirs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1–12MB
~74K SLoC