Yasec
Yet another stupid environment config (YASEC) creates settings from environment variables. (Envconig-rs fork)
Features
- Nested configuration structure.
- Inferring of an environment variable name. If a configuration field has name
password
then it gets value from environment variablePASSWORD
. If a configuration field is inside another structure and it has pathdb.password
it gets its value from variableDB_PASSWORD
. - Custom types.
- Option type is optional.
- Prefix of variables.
I implemented everything what I require when I develop an application. Feel free to open an issue of a feature you miss as well as a pull request.
Macro attributes
from
- name of an environment variable which provides a field value. Name of the field and name of the parent structures are ignored.default
- default value of a field if an environment variable doesn't exist. If the environment variable exist but has invalid value an error returns.
Usage
You can achieve this with the following code without boilerplate:
extern crate yasec_derive;
extern crate yasec;
use Error as StdError;
use Yasec;
Running tests
Tests do some manipulation with environment variables, so to prevent flaky tests they have to be executed in a single thread:
cargo test -- --test-threads=1
License
Licensed under MIT