Env Settings
Env Settings is a Rust library that helps you to initialize structs using environment variables
This Rust library took inspiration from
pydantic's BaseSettingsPython class
Installation
Usage
When you add the EnvSettings derive to a struct, two methods are added to it
-
It creates a new instance using just the environment variables. If something fails, it returns an
env_settings_utils::EnvSettingsErrorerror -
It creates a new instance using a combination of environment variables and parameters. More in detail, every field value can be passed as parameter wrapped in an
Optionobject. Then if the parameter isSome, it is used, otherwise the value is recoved from the environment variables. If something fails, it returns anenv_settings_utils::EnvSettingsErrorerror
Basic
use EnvSettings;
Advanced
use EnvSettings;
Parameters
The current supported parameters are:
case_insensitive: add it if the environment variables matching should be case insensitivedelay: add it to delay the lookup for environment variables from compilation time to run timefile_path: add it to specify a file path to read to add some environment variables (e.g..env)prefix: add it to specify a prefix to add to the name of the struct fields before matching the environment variables
Variables resolution hierarchy
- Arguments passed to the
newmethod (if usingnew). - Environment variables
- Variables loaded from a file (e.g.
.env)
Contribute
Before starting to work on a conribution please read:
Run tests
When testing run:
to prevent tests from competitively interacting with the same file
License
This project is licensed under the terms of the MIT or Apache 2.0 license.