Trait ConfigExt

Source
pub trait ConfigExt: Config {
    // Provided methods
    fn get_opt<T: FromConfig>(
        &self,
        section: &str,
        name: &str,
    ) -> Result<Option<T>> { ... }
    fn get_nonempty_opt<T: FromConfig>(
        &self,
        section: &str,
        name: &str,
    ) -> Result<Option<T>> { ... }
    fn get_or<T: FromConfig>(
        &self,
        section: &str,
        name: &str,
        default_func: impl Fn() -> T,
    ) -> Result<T> { ... }
    fn get_or_default<T: Default + FromConfig>(
        &self,
        section: &str,
        name: &str,
    ) -> Result<T> { ... }
    fn must_get<T: FromConfig>(&self, section: &str, name: &str) -> Result<T> { ... }
}
Expand description

Extra APIs (incompatible with trait objects) around reading config.

Provided Methods§

Source

fn get_opt<T: FromConfig>(&self, section: &str, name: &str) -> Result<Option<T>>

Get a config item. Convert to type T.

Source

fn get_nonempty_opt<T: FromConfig>( &self, section: &str, name: &str, ) -> Result<Option<T>>

Get a nonempty config item. Convert to type T.

Source

fn get_or<T: FromConfig>( &self, section: &str, name: &str, default_func: impl Fn() -> T, ) -> Result<T>

Get a config item. Convert to type T.

If the config item is not set, calculate it using default_func.

Source

fn get_or_default<T: Default + FromConfig>( &self, section: &str, name: &str, ) -> Result<T>

Get a config item. Convert to type T.

If the config item is not set, return T::default().

Source

fn must_get<T: FromConfig>(&self, section: &str, name: &str) -> Result<T>

Get a config item. Convert to type T.

If the config item is not set, return Error::NotSet.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Config> ConfigExt for T