Struct confik::EnvSource

source ·
pub struct EnvSource<'a> { /* private fields */ }
Available on crate feature env only.
Expand description

A Source referring to environment variables.

Uses the envious crate for interpreting env vars.

§Examples

use confik::{ConfigBuilder, Configuration, EnvSource};

#[derive(Configuration)]
struct Config {
    port: u16,
}

std::env::set_var("PORT", "1234");

let config = ConfigBuilder::<Config>::default()
    .override_with(EnvSource::new())
    .try_build()
    .unwrap();

assert_eq!(config.port, 1234);

Implementations§

source§

impl<'a> EnvSource<'a>

source

pub fn new() -> Self

Creates a new Source referring to environment variables.

source

pub fn with_prefix(self, prefix: &'a str) -> Self

Sets the envious prefix.

See envious::Config::with_prefix().

source

pub fn with_separator(self, separator: &'a str) -> Self

Sets the envious separator.

See envious::Config::with_separator().

source

pub fn with_config(self, config: Config<'a>) -> Self

Sets the envious config.

source

pub fn allow_secrets(self) -> Self

Allows this source to contain secrets.

Trait Implementations§

source§

impl<'a> Clone for EnvSource<'a>

source§

fn clone(&self) -> EnvSource<'a>

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<'a> Debug for EnvSource<'a>

source§

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

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

impl<'a> Default for EnvSource<'a>

source§

fn default() -> Self

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

impl<'a> Source for EnvSource<'a>

source§

fn allows_secrets(&self) -> bool

Whether this source is allowed to contain secret data. Read more
source§

fn provide<T: ConfigurationBuilder>( &self ) -> Result<T, Box<dyn Error + Sync + Send>>

Attempts to provide a partial configuration object from this source.

Auto Trait Implementations§

§

impl<'a> Freeze for EnvSource<'a>

§

impl<'a> RefUnwindSafe for EnvSource<'a>

§

impl<'a> Send for EnvSource<'a>

§

impl<'a> Sync for EnvSource<'a>

§

impl<'a> Unpin for EnvSource<'a>

§

impl<'a> UnwindSafe for EnvSource<'a>

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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.