Hierarchy

Struct Hierarchy 

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

Source

pub fn new() -> Self

Source

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

Source

pub fn as_vec(&self) -> &Vec<I>

Source§

impl<I: AsRef<str>> Hierarchy<I>

Source

pub fn join(&self, current: &str) -> String

Join the items in the hierarchy with the current item. The items are joined with a period. The generic type must implement AsRef<str>.

Example usage of Hierarchy

Source§

impl<I: ToString> Hierarchy<I>

Source

pub fn joining(&self, current: String) -> String

Join the items in the hierarchy with the current item. The items are joined with a period. The generic type must implement ToString.

Similarity Example usage of Hierarchy

Trait Implementations§

Source§

impl<I> Default for Hierarchy<I>

Source§

fn default() -> Self

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

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> 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> 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, 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.