Struct smart_config::Environment

source ·
pub struct Environment { /* private fields */ }
Expand description

Configuration sourced from environment variables.

Implementations§

source§

impl Environment

source

pub fn prefixed(prefix: &str) -> Self

Loads environment variables with the specified prefix.

source

pub fn from_iter<K, V>( prefix: &str, env: impl IntoIterator<Item = (K, V)>, ) -> Self
where K: AsRef<str> + Into<String>, V: Into<String>,

Creates a custom environment.

source

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.

source

pub fn iter(&self) -> impl ExactSizeIterator<Item = (&str, &WithOrigin)> + '_

Iterates over variables in this container.

source

pub fn strip_prefix(self, prefix: &str) -> Self

Strips a prefix from all contained vars and returns the filtered vars.

source

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.

source

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

source§

fn clone(&self) -> Environment

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl ConfigSource for Environment

§

type Kind = Flat

Kind of the source.
source§

fn into_contents(self) -> WithOrigin<Map>

Converts this source into config contents.
source§

impl Debug for Environment

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Environment

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more