Crates.io | configurs |
lib.rs | configurs |
version | 0.1.1 |
source | src |
created_at | 2020-07-30 12:38:44.593406 |
updated_at | 2020-07-30 12:48:43.764056 |
description | Mildly opinionated configuration management for Rust apps. |
homepage | https://gitlab.com/nikolaplejic/configurs/ |
repository | https://gitlab.com/nikolaplejic/configurs/ |
max_upload_size | |
id | 271262 |
size | 4,287 |
Mildly opinionated configuration management for Rust apps. Supports loading config values from environment variables, TOML files, and inline-annotated default values.
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.
file_loader
featureAdditional 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: