[][src]Struct justconfig::ConfPath

pub struct ConfPath { /* fields omitted */ }

An owned, immutable configuration path.

This type provides methods like push and pop. None of these methods visibly modifies self. All return a new ConfPath structure. This structure is only a refrence counted reference to the data of the path node. Therefore it can be cloned without much overhead.

An iter() method is provided for easy enumeration of the config paths components.

Examples

A configuration path can be built from an array of string references.

use justconfig::ConfPath;

let cp = ConfPath::from(&["a", "b"]);

Modifying a configuration path always returns a new path.

use justconfig::ConfPath;

let cp = ConfPath::default();
let cp_a = cp.push("a");

assert_eq!(cp, ConfPath::default());
assert_eq!(cp_a, ConfPath::from(&["a"]));

Details

The ConfPath structure internally creates a tree of all config nodes that where ever requested below the same root node. If you call push the new value will be stored within the parent node until the whole configuration tree gets torn down.

If you only want a temporary value, create a new configuration tree by using the from method.

The comparison method eq makes sure, that the same paths from different configuration trees compare equal. It uses a shortcut if the compared values originate from the same configuration tree.

Implementations

impl ConfPath[src]

pub fn push(&self, component: &str) -> Self[src]

Append a path component to this config path and return the new path. This path will not be modified.

Example

use justconfig::ConfPath;

let cp_a = ConfPath::default().push("a");
let cp_ab = cp_a.push("b");

assert_eq!(cp_ab, ConfPath::from(&["a", "b"]));

pub fn push_all<S: AsRef<str>, T: IntoIterator<Item = S>>(
    &self,
    iter: T
) -> Self
[src]

Append multiple path components to this config path and return the new path. This path will not be modified.

Example

use justconfig::ConfPath;

let cp_a = ConfPath::default().push("a");
let cp_abc = cp_a.push_all(&["b", "c"]);

assert_eq!(cp_abc, ConfPath::from(&["a", "b", "c"]));

pub fn pop(&self) -> Option<(&str, Self)>[src]

Remove the last component from this config path and return a new config path and the removed component.

The method returns a tuple containing an Option that stores the removed path component and a new config path containing the remaining path. If the config path is empty, the first element of the tuple is None.

Example

use justconfig::ConfPath;

let cp = ConfPath::default().push_all(&["a", "b"]);

let (component, cp) = cp.pop().unwrap();
assert_eq!(component, "b");

let (component, cp) = cp.pop().unwrap();
assert_eq!(component, "a");

assert!(cp.pop().is_none());

pub fn is_root(&self) -> bool[src]

Checks if this ConfPath node is the root-node of the config path

This method returns true if this node is the root node of the config path.

Example

use justconfig::ConfPath;

let cp = ConfPath::default();
let cp_a = cp.push("a");

assert!(cp.is_root());
assert!(!cp_a.is_root());

pub fn tail_component_name(&self) -> Option<&str>[src]

Returns the name of the last component of this config path.

If this method is called on the root of a ConfPath tree None is returned.

Example

use justconfig::ConfPath;

let cp = ConfPath::default().push_all(&["first", "second", "last"]);

assert_eq!(cp.tail_component_name().unwrap(), "last");

pub fn iter(&self) -> impl Iterator<Item = Self>[src]

Returns an iterator that enumerates the components of the path.

The iterator returns the components first to last. Starting with the component directly below the root of the tree.

pub fn children(&self) -> impl Iterator<Item = ConfPath>[src]

Returns an iterator that returns the children of the path element.

The children are not returned in any particular order. The iterator takes a snapshot of the current tree node. Therefore it's ok to update the config path while this iterator is used.

Example

use justconfig::ConfPath;

let cp = ConfPath::default().push_all(&["first", "second", "last"]);

for child in cp.children() {
  println!("{}", child.tail_component_name().unwrap());
}

Trait Implementations

impl Add<&'_ str> for ConfPath[src]

type Output = Self

The resulting type after applying the + operator.

impl Clone for ConfPath[src]

impl Debug for ConfPath[src]

impl Default for ConfPath[src]

impl Display for ConfPath[src]

impl Eq for ConfPath[src]

impl<'a, T: AsRef<[&'a str]>> From<T> for ConfPath[src]

impl Hash for ConfPath[src]

impl IntoIterator for ConfPath[src]

type Item = ConfPath

The type of the elements being iterated over.

type IntoIter = Rev<IntoIter<Self>>

Which kind of iterator are we turning this into?

impl PartialEq<ConfPath> for ConfPath[src]

Auto Trait Implementations

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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.