Environment

Struct Environment 

Source
pub struct Environment { /* private fields */ }

Implementations§

Source§

impl Environment

Source

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

Create a new environment configuration which will prefix keys with the given prefix and an underscore (e.g. prefix = “foo” => “foo_*”). An empty prefix will not prepend anything.

Getting a value from the environment will try to make the key more environment-variable-like . ‘.’ and ‘/’ are replaced with ‘_’ and everything is upper-cased. If the prefix is ‘foo’, then a get for ‘my.app.secret’ would look for ‘FOO_MY_APP_SECRET’.

Trait Implementations§

Source§

impl Config for Environment

Source§

fn get(&self, key: &str) -> Option<String>

Get a value from the environment using the given key. ‘.’ and ‘/’ are replaced with ‘_’ and everything is upper-cased. If the prefix is ‘foo’, then a get for ‘my.app.secret’ would look for ‘FOO_MY_APP_SECRET’.

Source§

fn must_get(&self, key: &str) -> String

Similar to get but panics if there is no value.
Source§

fn string(&self, key: &str) -> String

Get the value as a string or panics if one isn’t found.
Source§

fn int(&self, key: &str) -> i64

Get the value as an integer or panics if one isn’t found or cannot be parsed.
Source§

fn float(&self, key: &str) -> f64

Get the value as a float or panics if one isn’t found or cannot be parsed.
Source§

fn bool(&self, key: &str) -> bool

Get the value as a bool or panics if one isn’t found or cannot be parsed. The following case-insensitive values are considered true: t, true, 1, y, yes. All other values are considered false.
Source§

fn duration(&self, key: &str) -> Duration

Get the value as a duration or panics if one isn’t found or can’t be parsed. Thre doesn’t appear to be a parsing function for a duration, so it attempts to convert to an integer and use that as the number of seconds.
Source§

fn datetime(&self, key: &str) -> DateTime<Utc>

Get the value as a duration or panics if one isn’t found or it can’t be parsed. It uses RFC339 to parse it.
Source§

fn list(&self, key: &str) -> Vec<String>

Get a list or panics if one isn’t found. The list should be a comma-delimited list surrouned by brackets (e.g. [1, 2, 3] => vec![“1”, “2”, “3”].
Source§

fn map(&self, key: &str) -> HashMap<String, String>

Get a map or panics if one isn’t found. The list should be a comma-delimited list surrouned by braces with key/value pairs associated with => (e.g. {a=>1, b=>2, c=>3} => ((a,1), (b,2), (c,3))).
Source§

impl Debug for Environment

Source§

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

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

impl PartialEq for Environment

Source§

fn eq(&self, other: &Environment) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Environment

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.