configurs

Crates.ioconfigurs
lib.rsconfigurs
version0.1.1
sourcesrc
created_at2020-07-30 12:38:44.593406
updated_at2020-07-30 12:48:43.764056
descriptionMildly opinionated configuration management for Rust apps.
homepagehttps://gitlab.com/nikolaplejic/configurs/
repositoryhttps://gitlab.com/nikolaplejic/configurs/
max_upload_size
id271262
size4,287
Nikola Plejic (nikolaplejic)

documentation

https://gitlab.com/nikolaplejic/configurs/

README

Configurs

Mildly opinionated configuration management for Rust apps. Supports loading config values from environment variables, TOML files, and inline-annotated default values.

Usage

Add this to your [dependencies] section of Cargo.toml:

configurs = "0.1"
configurs_derive = { version = "0.1" }

...or, if you'd like to use the option to load configuration from a TOML file:

configurs = "0.1"
configurs_derive = { version = "0.1", features = ["file_loader"] }

Then, and annotate your struct:

use configurs_derive::Configuration;

#[derive(Configuration)]
struct Configuration {
    #[env="PORT"]
    #[default="8088"]
    port: i16,

    #[env="HOST"]
    #[default="127.0.0.1"]
    host: String,
}

fn main() {
    let config = Configuration::load();
}

Running the program with HOST or PORT environment variables will now override the annotated defaults.

Using the file_loader feature

Additional dependencies:

serde = "1"
serde_derive = "1"
toml = "0.5"

Usage:

use serde_derive::Deserialize;

#[derive(Configuration, Deserialize)]
#[serde(default)]
struct Configuration {
    #[env="PORT"]
    #[default="8088"]
    port: i16,

    #[env="HOST"]
    #[default="127.0.0.1"]
    host: String,
}

fn main() {
    let config = Configuration::load_from_file("./Config.toml");
}

The values will be loaded in the following order or precedence:

  1. env variables
  2. config file
  3. annotated defaults
Commit count: 15

cargo fmt