pub struct DeserializerConfig { /* private fields */ }Expand description
Configures how environment variables are deserialized.
The configuration is independent of the environment so it can be
created once (even as a constant) and used many times. The methods
from_env and from_vars work like
the functions of the same name.
use std::collections::BTreeMap;
use deser_env::DeserializerConfig;
const CONFIG: DeserializerConfig =
DeserializerConfig::builder().separator("_").build();
let value: BTreeMap<String, BTreeMap<String, u32>> =
CONFIG.from_vars("APP_", [("APP_SERVER_PORT", "80")]).unwrap();
assert_eq!(value["server"]["port"], 80);Implementations§
Source§impl DeserializerConfig
impl DeserializerConfig
Sourcepub const fn new() -> DeserializerConfig
pub const fn new() -> DeserializerConfig
Creates the default configuration.
Sourcepub const fn builder() -> DeserializerConfigBuilder
pub const fn builder() -> DeserializerConfigBuilder
Returns a builder for the configuration (see DeserializerConfigBuilder).
Sourcepub const fn into_builder(self) -> DeserializerConfigBuilder
pub const fn into_builder(self) -> DeserializerConfigBuilder
Returns a builder that starts with this configuration.
Sourcepub fn set_context(&mut self, context: Context)
pub fn set_context(&mut self, context: Context)
Sets the context the values are deserialized in.
The values of the context are the defaults of the extension values
of the state (see Context), for instance
the variants of open enums. The deserializers and readers created
with the configuration use this context. A context set
on the driver takes precedence.
Sourcepub const fn set_separator(&mut self, separator: &'static str)
pub const fn set_separator(&mut self, separator: &'static str)
Sets the separator of nested keys.
The default is __ (APP_SERVER__PORT is server.port). A single
_ cannot be told apart from the underscores in names, so
APP_MAX_CONNECTIONS would be max.connections. The empty string
disables nesting, names are keys as they are.
Sourcepub const fn set_case(&mut self, case: Case)
pub const fn set_case(&mut self, case: Case)
Sets how the case of names maps onto keys.
The default is Case::Upper which lowercases the names.
Sourcepub const fn set_max_depth(&mut self, depth: usize)
pub const fn set_max_depth(&mut self, depth: usize)
Sets how deeply keys can be nested.
This is the number of separators in a name (after the prefix). Names that are nested deeper are an error. The default is 16.