Skip to main content

ConfigLookup

Struct ConfigLookup 

Source
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>

Source

pub fn get<'step>(&'step self, key: &'step str) -> ConfigLookup<'config, 'step>

Select a child key from the current lookup value.

Source

pub fn get_index<'step>( &'step self, index: usize, ) -> ConfigLookup<'config, 'step>

Select a child index from the current lookup value.

Source

pub fn value(&self) -> Result<&'config ConfigValue, ConfigError>

Return the underlying value or the captured path error.

Source

pub fn as_string(&self) -> Result<String, ConfigError>

Return the selected value as a string.

Source

pub fn as_i64(&self) -> Result<i64, ConfigError>

Return the selected value as an integer.

Source

pub fn as_f64(&self) -> Result<f64, ConfigError>

Return the selected value as a float.

Source

pub fn as_bool(&self) -> Result<bool, ConfigError>

Return the selected value as a boolean.

Source

pub fn as_datetime(&self) -> Result<&'config Datetime, ConfigError>

Return the selected value as a TOML datetime.

Source

pub fn as_bytes(&self) -> Result<u64, ConfigError>

Return the selected value as a byte size.

Source

pub fn as_duration(&self) -> Result<Duration, ConfigError>

Return the selected value as a duration.

Source

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());
Source

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>

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<'config, 'path> Debug for ConfigLookup<'config, 'path>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for ConfigLookup<'_, '_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, SerError>

Tries to produce a copy of self or returns an error
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Erased for T