deser-env
Environment variables for deser.
The variables with a prefix are read as a map, __ separates nested keys
(a single _ separates words in names). Everything in the environment is
text, only the type a value is deserialized into knows what it means.
deser passes the text on as lexical atoms which are parsed by the type they
end up in, also after buffering, so numbers parse in flattened structs and
internally tagged enums:
use ;
use ;
// `deser_env::from_env("APP_")` reads the environment of the process
let config: Config = from_vars
.unwrap;
assert_eq!;
assert_eq!;
let vars = to_vars.unwrap;
assert_eq!;
What works:
- Nested structs, maps and enums (
APP_SERVER__PORT), sequences with indexes (APP_HOSTS__0) and lists in one variable with theSeparatedadapter (APP_HOSTS=a,b). - Names are lowercased (
Case::Preservekeeps them), the separator can be configured. - Empty values are
Nonefor optionals of types that do not accept them (APP_PORT=for anOption<u16>). TheFlagadapter makes a variable that is set but emptytrue. - Errors (also of unknown fields collected as warnings) carry the name of the variable.
- Updating an existing value, for instance to override a configuration file.
- Serializing into name-value pairs, for instance for
Command::envs.
License and Links
- Issue Tracker
- Documentation
- License: Apache-2.0