pub struct ConfPath { /* private fields */ }
Expand description

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

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"]));

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"]));

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

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

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");

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.

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

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.