pub struct ConfigLookup<'config, 'path> { /* private fields */ }Expand description
A fallible config path lookup that carries the traversed path for later conversions.
'config: lifetime of the selected value borrowed from the underlying config tree.'path: lifetime of any borrowed path fragments and the parent lookup chain that are used to render detailed path errors lazily.
Implementations§
Source§impl<'config, 'path> ConfigLookup<'config, 'path>
impl<'config, 'path> ConfigLookup<'config, 'path>
Sourcepub fn get<'step>(&'step self, key: &'step str) -> ConfigLookup<'config, 'step>
pub fn get<'step>(&'step self, key: &'step str) -> ConfigLookup<'config, 'step>
Select a child key from the current lookup value.
Sourcepub fn get_index<'step>(
&'step self,
index: usize,
) -> ConfigLookup<'config, 'step>
pub fn get_index<'step>( &'step self, index: usize, ) -> ConfigLookup<'config, 'step>
Select a child index from the current lookup value.
Sourcepub fn value(&self) -> Result<&'config ConfigValue, ConfigError>
pub fn value(&self) -> Result<&'config ConfigValue, ConfigError>
Return the underlying value or the captured path error.
Sourcepub fn as_string(&self) -> Result<String, ConfigError>
pub fn as_string(&self) -> Result<String, ConfigError>
Return the selected value as a string.
Sourcepub fn as_i64(&self) -> Result<i64, ConfigError>
pub fn as_i64(&self) -> Result<i64, ConfigError>
Return the selected value as an integer.
Sourcepub fn as_f64(&self) -> Result<f64, ConfigError>
pub fn as_f64(&self) -> Result<f64, ConfigError>
Return the selected value as a float.
Sourcepub fn as_bool(&self) -> Result<bool, ConfigError>
pub fn as_bool(&self) -> Result<bool, ConfigError>
Return the selected value as a boolean.
Sourcepub fn as_datetime(&self) -> Result<&'config Datetime, ConfigError>
pub fn as_datetime(&self) -> Result<&'config Datetime, ConfigError>
Return the selected value as a TOML datetime.
Sourcepub fn as_bytes(&self) -> Result<u64, ConfigError>
pub fn as_bytes(&self) -> Result<u64, ConfigError>
Return the selected value as a byte size.
Sourcepub fn as_duration(&self) -> Result<Duration, ConfigError>
pub fn as_duration(&self) -> Result<Duration, ConfigError>
Return the selected value as a duration.
Sourcepub fn as_array(&self) -> Result<&'config [ConfigValue], ConfigError>
pub fn as_array(&self) -> Result<&'config [ConfigValue], ConfigError>
Return the selected value as an array slice.
use kompact::config::parse_config_str;
let conf = parse_config_str("values = [1, 2, 3]").expect("config");
let values = conf.select("values").as_array().expect("array");
assert_eq!(3, values.len());Sourcepub fn array_entries<'lookup>(
&'lookup self,
) -> Result<ConfigArrayIter<'config, 'lookup, 'path>, ConfigError>
pub fn array_entries<'lookup>( &'lookup self, ) -> Result<ConfigArrayIter<'config, 'lookup, 'path>, ConfigError>
Iterate over the selected array value with path-aware element lookups.
use kompact::config::parse_config_str;
let conf = parse_config_str(r#"
[[routes]]
alias = "first"
[[routes]]
alias = "second"
"#).expect("config");
let routes = conf.select("routes");
let mut aliases = Vec::new();
for (_, route) in routes.array_entries().expect("array") {
aliases.push(route.get("alias").as_string().expect("alias"));
}
assert_eq!(vec!["first".to_string(), "second".to_string()], aliases);Trait Implementations§
Source§impl<'config, 'path> Clone for ConfigLookup<'config, 'path>
impl<'config, 'path> Clone for ConfigLookup<'config, 'path>
Source§fn clone(&self) -> ConfigLookup<'config, 'path>
fn clone(&self) -> ConfigLookup<'config, 'path>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'config, 'path> Debug for ConfigLookup<'config, 'path>
impl<'config, 'path> Debug for ConfigLookup<'config, 'path>
Source§impl Display for ConfigLookup<'_, '_>
impl Display for ConfigLookup<'_, '_>
impl<'config, 'path> Copy for ConfigLookup<'config, 'path>
Auto Trait Implementations§
impl<'config, 'path> Freeze for ConfigLookup<'config, 'path>
impl<'config, 'path> !RefUnwindSafe for ConfigLookup<'config, 'path>
impl<'config, 'path> !Send for ConfigLookup<'config, 'path>
impl<'config, 'path> !Sync for ConfigLookup<'config, 'path>
impl<'config, 'path> Unpin for ConfigLookup<'config, 'path>
impl<'config, 'path> UnsafeUnpin for ConfigLookup<'config, 'path>
impl<'config, 'path> !UnwindSafe for ConfigLookup<'config, 'path>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more