pub struct Hierarchy<I> { /* private fields */ }Expand description
A simple stack-like structure that can be used to keep track of a hierarchy. This is useful for keeping track of a hierarchy of items, such as a hierarchy of keys.
§Example
use local_fmt_macros_internal::utils::hierarchy::Hierarchy;
let mut hierarchy = Hierarchy::new();
hierarchy.process("a", |h| {
h.process("b", |h| {
assert_eq!(h.join("key"), "a.b.key");
});
assert_eq!(h.join("key"), "a.key");
});
assert_eq!(hierarchy.join("key"), "key");Implementations§
Source§impl<I> Hierarchy<I>
impl<I> Hierarchy<I>
pub fn new() -> Self
Sourcepub fn process<T>(&mut self, item: I, func: impl FnOnce(&mut Self) -> T) -> T
pub fn process<T>(&mut self, item: I, func: impl FnOnce(&mut Self) -> T) -> T
Process an item and a function that takes a mutable reference to the hierarchy. The item is pushed onto the hierarchy before the function is called and popped off after the function is called. Example usage of Hierarchy
pub fn as_vec(&self) -> &Vec<I>
Trait Implementations§
Auto Trait Implementations§
impl<I> Freeze for Hierarchy<I>
impl<I> RefUnwindSafe for Hierarchy<I>where
I: RefUnwindSafe,
impl<I> Send for Hierarchy<I>where
I: Send,
impl<I> Sync for Hierarchy<I>where
I: Sync,
impl<I> Unpin for Hierarchy<I>where
I: Unpin,
impl<I> UnwindSafe for Hierarchy<I>where
I: UnwindSafe,
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