Struct smart_config::Environment
source · 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 moresource§impl ConfigSource for Environment
impl ConfigSource for Environment
source§fn into_contents(self) -> WithOrigin<Map>
fn into_contents(self) -> WithOrigin<Map>
source§impl Debug for Environment
impl Debug for Environment
Auto Trait Implementations§
impl Freeze for Environment
impl RefUnwindSafe for Environment
impl Send for Environment
impl Sync for Environment
impl Unpin for Environment
impl UnwindSafe for Environment
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)