Crates.io | configurs_derive |
lib.rs | configurs_derive |
version | 0.1.0 |
source | src |
created_at | 2020-07-30 12:38:36.672581 |
updated_at | 2020-07-30 12:38:36.672581 |
description | Macro implementations for configurs, the configuration loader for Rust apps. |
homepage | https://gitlab.com/nikolaplejic/configurs/ |
repository | https://gitlab.com/nikolaplejic/configurs/ |
max_upload_size | |
id | 271261 |
size | 6,847 |
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: