ConfBuilder

Struct ConfBuilder 

Source
pub struct ConfBuilder<S, F = fn(&dyn ConfigEvent)>
where S: Conf, F: FnMut(&dyn ConfigEvent),
{ /* private fields */ }
Expand description

A builder which collects config value sources and other options, before parsing your struct.

If args is not set, the default source is std::env::args_os. If env is not set, the default source is std::env::vars_os.

Implementations§

Source§

impl<S, F> ConfBuilder<S, F>
where S: Conf, F: FnMut(&dyn ConfigEvent),

Source

pub fn args(self, args: impl IntoIterator<Item: Into<OsString>>) -> Self

Set the CLI args used in this parse

Source

pub fn env<K, V>(self, env: impl IntoIterator<Item = (K, V)>) -> Self
where K: Into<OsString>, V: Into<OsString>,

Set the env vars used in this parse

Source

pub fn config_logger<F2: FnMut(&dyn ConfigEvent)>( self, f: F2, ) -> ConfBuilder<S, F2>

Set the config logger used in this parse This enables introspection on the config process, so that it can be determined which program options are configured via which value sources.

Source

pub fn parse(self) -> S

Parse based on supplied sources (or falling back to defaults), and exiting the program with errors logged to stderr if parsing fails.

Source

pub fn try_parse(self) -> Result<S, Error>

Try to parse an instance based on supplied sources (or falling back to defaults), returning an error if parsing fails.

Source§

impl<S, F> ConfBuilder<S, F>
where S: ConfSerde, F: FnMut(&dyn ConfigEvent),

Source

pub fn doc<'de, D: Deserializer<'de>>( self, document_name: impl Into<String>, deserializer: D, ) -> ConfSerdeBuilder<'de, D, S, F>

Set the document used in this parse.

Requires a name for the document and a serde Deserializer representing the content.

The name is typically the name of a file, and is used in error messages.

The deserializer is, for example, a serde_json::Value, serde_yaml::Value, figment::Value, etc. which you have already loaded from disk and parsed in an unstructured way.

Trait Implementations§

Source§

impl<S, F> Default for ConfBuilder<S, F>
where S: Conf, F: FnMut(&dyn ConfigEvent),

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S, F> Freeze for ConfBuilder<S, F>
where F: Freeze,

§

impl<S, F> RefUnwindSafe for ConfBuilder<S, F>
where F: RefUnwindSafe,

§

impl<S, F> Send for ConfBuilder<S, F>
where F: Send,

§

impl<S, F> Sync for ConfBuilder<S, F>
where F: Sync,

§

impl<S, F> Unpin for ConfBuilder<S, F>
where F: Unpin,

§

impl<S, F> UnwindSafe for ConfBuilder<S, F>
where F: UnwindSafe,

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.