Struct miau::configuration::Lens[][src]

pub struct Lens<'config> { /* fields omitted */ }

Provides lensing capabilities to a configuration reader.

Allows scoping into configuration section of choice for read only access. It can be seen as a borrowed version of Configuration.

To read values from Lens you need to pull ConfigurationRead in scope.

Example

use miau::configuration::{Configuration, ConfigurationRead};

let configuration = Configuration::default(); //  aka empty

let lens = configuration.lens();
match lens.try_lens("key") {
    Ok(descended) => {
        let word: Option<String> = lens.get("word");
        assert_eq!(None, word);
    }
    // lensing operation can fail if e.g key is unparsable
    Err(e) => println!("Oh no! {}", e),
};

Implementations

impl<'config> Lens<'config>[src]

pub fn new_singular(def: &'config ConfigurationDefinition) -> Self[src]

Creates new instance of Lens from a single configuration definition.

Such lens might be useful to scope into configurations section of interest to reduce path length needed to retrive values.

pub fn new(config: &'config Configuration) -> Self[src]

Creates new instance of Lens from Configuration.

It enables lensing into multiple configuration trees at once. It handles situation like possibility of absence of given subtree in subset of configuration trees. When substree is missing, given tree is simply ignored in lens.

pub fn try_lens<S>(&self, keys: S) -> Result<Self, ConfigurationError> where
    S: TryInto<CompoundKey, Error = ConfigurationError>, 
[src]

Attempts to lens into given Lens

Function can only return error if transformation of keys failed. If none of configuration trees contains requested key, empty Lens will be returned.

pub fn try_convert_into<T: DeserializeOwned>(
    self
) -> Result<T, ConfigurationError>
[src]

Deserializes Lens into strongly typed struct.

It is only required that struct to be deserialized to implements Deserialize and contains no borrowed fields, for instance &str. Due to memory model of miau it is impossible to deserialize into such fields.

pub fn merge_cloned(self) -> Result<ConfigurationTree, ConfigurationError>[src]

Merges trees contained in Lens into one tree by cloning them.

Trait Implementations

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

impl<'config> Debug for Lens<'config>[src]

impl<'config> From<&'config Configuration> for Lens<'config>[src]

impl<'config> From<&'config ConfigurationDefinition> for Lens<'config>[src]

Auto Trait Implementations

impl<'config> RefUnwindSafe for Lens<'config>[src]

impl<'config> Send for Lens<'config>[src]

impl<'config> Sync for Lens<'config>[src]

impl<'config> Unpin for Lens<'config>[src]

impl<'config> UnwindSafe for Lens<'config>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.