pub struct Environment { /* private fields */ }Expand description
Configuration sourced from environment variables.
Implementations§
Source§impl Environment
impl Environment
Sourcepub fn from_iter<K, V>(
prefix: &str,
env: impl IntoIterator<Item = (K, V)>,
) -> Self
pub fn from_iter<K, V>( prefix: &str, env: impl IntoIterator<Item = (K, V)>, ) -> Self
Creates a custom environment.
Sourcepub fn with_vars(self, var_names: &[&str]) -> Self
pub fn with_vars(self, var_names: &[&str]) -> Self
Adds additional variables to this environment. This is useful if the added vars don’t have the necessary prefix.
Sourcepub fn iter(&self) -> impl ExactSizeIterator<Item = (&str, &WithOrigin)> + '_
pub fn iter(&self) -> impl ExactSizeIterator<Item = (&str, &WithOrigin)> + '_
Iterates over variables in this container.
Sourcepub fn strip_prefix(self, prefix: &str) -> Self
pub fn strip_prefix(self, prefix: &str) -> Self
Strips a prefix from all contained vars and returns the filtered vars.
Sourcepub fn coerce_json(&mut self) -> Result<()>
pub fn coerce_json(&mut self) -> Result<()>
Coerces JSON values in env variables which names end with the __json / :json suffixes and strips this suffix.
§Errors
Returns an error if any coercion fails; provides a list of all failed coercions. Successful coercions are still applied in this case.
Sourcepub fn convert_flat_params(
flat_params: &Map<String, Value>,
prefix: &str,
) -> Map<String, Value>
pub fn convert_flat_params( flat_params: &Map<String, Value>, prefix: &str, ) -> Map<String, Value>
Converts a flat configuration object into a flat object
usable as the env var specification for Docker Compose etc. It uppercases and prefixes param names,
replacing .s with _s, and replaces object / JSON params with strings so that they can be parsed
via JSON coercion.
§Important
Beware that additional transforms may be required depending on the use case. E.g., Docker Compose requires to escape Boolean values and nulls to strings.
Trait Implementations§
Source§impl Clone for Environment
impl Clone for Environment
Source§fn clone(&self) -> Environment
fn clone(&self) -> Environment
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more