pub struct ConfigLoader<'a> { /* private fields */ }
Expand description

Config

Implementations§

source§

impl<'a> ConfigLoader<'a>

source

pub const fn new(app_name: &'a str) -> ConfigLoader<'a>

Creates a new config loader for the provided app name. Uses a default file name of “config” and all formats.

source

pub fn with_file_name(&mut self, file_name: &'a str) -> &Self

Specifies the file name to look for, excluding the extension.

If not specified, defaults to “config”.

source

pub fn with_formats(&mut self, formats: &'a [Format]) -> &Self

Specifies which file formats to search for, and in which order.

If not specified, all formats are checked for in the order JSON, YAML, TOML, Corn.

source

pub fn with_config_dir(&mut self, dir: &'a str) -> &Self

Specifies which directory the config should be loaded from.

If not specified, loads from $XDG_CONFIG_DIR/<app_name> or $HOME/.<app_name> if the config dir does not exist.

source

pub fn find_and_load<T: DeserializeOwned>(&self) -> Result<T, UniversalConfig>

Attempts to locate a config file on disk and load it.

Errors

Will return a UniversalConfigError if any error occurs when looking for, reading, or deserializing a config file.

source

pub fn load<T: DeserializeOwned, P: AsRef<Path>>( path: P ) -> Result<T, UniversalConfig>

Loads the file at the given path, deserializing it into a new T.

The type is automatically determined from the file extension.

Errors

Will return a UniversalConfigError if unable to read or deserialize the file.

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for ConfigLoader<'a>

§

impl<'a> Send for ConfigLoader<'a>

§

impl<'a> Sync for ConfigLoader<'a>

§

impl<'a> Unpin for ConfigLoader<'a>

§

impl<'a> UnwindSafe for ConfigLoader<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

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

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

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 Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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