Struct justconfig::ConfPath
source · [−]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
sourceimpl ConfPath
impl ConfPath
sourcepub fn push(&self, component: &str) -> Self
pub fn push(&self, component: &str) -> Self
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"]));
sourcepub fn push_all<S: AsRef<str>, T: IntoIterator<Item = S>>(
&self,
iter: T
) -> Self
pub fn push_all<S: AsRef<str>, T: IntoIterator<Item = S>>(
&self,
iter: T
) -> Self
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"]));
sourcepub fn pop(&self) -> Option<(&str, Self)>
pub fn pop(&self) -> Option<(&str, Self)>
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());
sourcepub fn is_root(&self) -> bool
pub fn is_root(&self) -> bool
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());
sourcepub fn tail_component_name(&self) -> Option<&str>
pub fn tail_component_name(&self) -> Option<&str>
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");
sourcepub fn iter(&self) -> impl Iterator<Item = Self>
pub fn iter(&self) -> impl Iterator<Item = Self>
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.
sourcepub fn children(&self) -> impl Iterator<Item = ConfPath>
pub fn children(&self) -> impl Iterator<Item = ConfPath>
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
sourceimpl IntoIterator for ConfPath
impl IntoIterator for ConfPath
impl Eq for ConfPath
Auto Trait Implementations
impl !RefUnwindSafe for ConfPath
impl !Send for ConfPath
impl !Sync for ConfPath
impl Unpin for ConfPath
impl !UnwindSafe for ConfPath
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more