Struct irx_config::config::Config

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

Container for all parser sources which will (re)load data from a parsers in order in which they was added to ConfigBuilder. It will provide access to merged set of (re)loaded configuration parameters.

Implementations§

source§

impl Config

source

pub fn reload(&mut self) -> Result<&mut Self>

Reload and re-merge all configuration data from parsers.

Errors

If any errors will occur during parsing/merging then error will be returned.

source

pub fn hash(&self) -> String

Calculate hash for currently loaded configuration data.

source

pub fn get_by_keys<I, K, T>(&self, keys: I) -> Result<Option<T>>
where I: IntoIterator<Item = K>, K: AsRef<str>, T: DeserializeOwned,

Returns configuration data value to corresponding key/nested keys.

Example
let name: Option<u32> = conf.get_by_keys(["logger", "name"])?;
Errors

If keys is empty, the error will be returned.

source

pub fn get_by_key_path<T, P>(&self, path: P) -> Result<Option<T>>
where T: DeserializeOwned, P: AsRef<str>,

Returns configuration data value to corresponding key path with keys delimiter. Default delimiter is DEFAULT_KEYS_SEPARATOR.

Example
use serde::Deserialize;

#[derive(Deserialize)]
struct Person {
    first_name: String,
    last_name: String,
    age: u8,
}

let person: Option<Person> = conf.get_by_key_path("contact:info")?;
Errors

If keys path or keys delimiter is empty, the corresponding error will be returned.

source

pub fn get_by_key_path_with_delim<T, P, D>( &self, path: P, delim: D ) -> Result<Option<T>>
where T: DeserializeOwned, P: AsRef<str>, D: AsRef<str>,

Returns configuration data value to corresponding key path with delimiter.

Example
let name: Option<u32> = conf.get_by_key_path_with_delim("logger:name", ":")?;
Errors

If keys path or delimiter is empty, the corresponding error will be returned.

source

pub fn get<T: DeserializeOwned>(&self) -> Result<T>

Deserialize configuration to destination struct/value.

Example
use serde::Deserialize;

#[derive(Deserialize)]
struct Person {
    first_name: String,
    last_name: String,
    age: u8,
}

let person: Person = conf.get()?;
Errors

In case of any de-serialization problems the corresponding error will be returned.

source

pub fn get_value(&self) -> &Value

Get reference to internal Value structure.

Trait Implementations§

source§

impl Debug for Config

source§

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

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

impl Display for Config

source§

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

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

impl Ord for Config

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Config

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Config

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Config

Auto Trait Implementations§

§

impl !RefUnwindSafe for Config

§

impl !Send for Config

§

impl !Sync for Config

§

impl Unpin for Config

§

impl !UnwindSafe for Config

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.