Struct miau::configuration::Lens [−][src]
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]
S: TryInto<CompoundKey, Error = ConfigurationError>,
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]
self
) -> Result<T, ConfigurationError>
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]
T: TryFrom<&'config Value, Error = ConfigurationError>,
K: TryInto<CompoundKey, Error = ConfigurationError>,
fn get_result(&'config self, keys: K) -> Result<Option<T>, ConfigurationError>
[src]
fn get(&'config self, keys: K) -> Option<T>
[src]
impl<'config> Debug for Lens<'config>
[src]
impl<'config> From<&'config Configuration> for Lens<'config>
[src]
fn from(config: &'config Configuration) -> Self
[src]
impl<'config> From<&'config ConfigurationDefinition> for Lens<'config>
[src]
fn from(config: &'config ConfigurationDefinition) -> Self
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,