ConfigurationRead

Trait ConfigurationRead 

Source
pub trait ConfigurationRead<'config, T, K> {
    // Required method
    fn get_result(
        &'config self,
        keys: K,
    ) -> Result<Option<T>, ConfigurationError>;

    // Provided method
    fn get(&'config self, keys: K) -> Option<T> { ... }
}
Expand description

Represents object from which configuration can be read.

Required Methods§

Source

fn get_result(&'config self, keys: K) -> Result<Option<T>, ConfigurationError>

Retrieves value stored in ConfigurationTree under given keys.

If key transformation fails error is returned. Value is returned if found, None otherwise.

§Example
 //you need to have ConfigurationRead in scope
use miau::configuration::{Configuration, ConfigurationRead};
use miau::error::ConfigurationError;

let configuration = Configuration::default(); //  aka empty
let word: Result<Option<String>, ConfigurationError> = configuration.get_result("word");
match word {
     Ok(maybe_word) => {
         assert_eq!(None, maybe_word);
     },
     Err(e) => println!("Oh no! {}", e)
};

Provided Methods§

Source

fn get(&'config self, keys: K) -> Option<T>

Retrieves value stored in configuration under given keys.

If no value is found or key transformation fails None is returned. get_result provides more insight into root cause of error.

§Example
 //you need to have ConfigurationRead in scope
use miau::configuration::{Configuration, ConfigurationRead};

let configuration = Configuration::default(); //  aka empty
let word: Option<String> = configuration.get("word");
assert_eq!(None, word);

Implementors§

Source§

impl<'config, T, K> ConfigurationRead<'config, T, K> for ConfigurationTree
where T: TryFrom<&'config Value, Error = ConfigurationError>, K: TryInto<CompoundKey, Error = ConfigurationError>,

Source§

impl<'config, T, K> ConfigurationRead<'config, T, K> for Configuration
where T: TryFrom<&'config Value, Error = ConfigurationError>, K: TryInto<CompoundKey, Error = ConfigurationError>,

Source§

impl<'config, T, K> ConfigurationRead<'config, T, K> for Lens<'config>
where T: TryFrom<&'config Value, Error = ConfigurationError>, K: TryInto<CompoundKey, Error = ConfigurationError>,