Struct nb_tree::prelude::Path

source ·
pub struct Path<B: Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> { /* private fields */ }
Expand description

A path to a [Tree] node A Path is a collection of branches to follow to get to the desired node. An empty Path represents the root of the [Tree].

§Examples

use nb_tree::prelude::{Tree, Path};
let mut tree = Tree::new();
// Paths from string litterals, vectors, or manually built
let path_d: Path<String> = "/b/d".into();
//let path_e: Path<String> = vec!["a", "c", "e"].into();
//let mut path_f = Path::new();
//path_f.l("b").l("f");
// Use paths to insert data
tree.i("/", 0)
    .i("/a", 1)
    .i("/b", 2)
    .i("/a/c", 3)
    .i(path_d, 4)
//    .i(path_e, 5)
    .i("/a/c/e", 5)
    .i("/b/f", 6);
//    .i(path_f, 6);

// Use paths to retrieve data
assert_eq!(tree.get(&"/a/c".into()), Ok(&3));

// Use paths to remove data
//tree.remove_sub_tree()
//assert

Implementations§

source§

impl<B: Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> Path<B>

source

pub fn new() -> Self

source

pub fn pop_root(&mut self) -> Option<B>

source

pub fn pop_leaf(&mut self) -> Option<B>

source

pub fn push_leaf(&mut self, value: B)

source

pub fn push_root(&mut self, value: B)

source

pub fn last(&self) -> Option<&B>

source

pub fn first(&self) -> Option<&B>

source

pub fn iter(&self) -> Iter<'_, B>

Trait Implementations§

source§

impl<B: Clone + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> Clone for Path<B>

source§

fn clone(&self) -> Path<B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<B: Debug + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> Debug for Path<B>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<B: Default + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> Default for Path<B>

source§

fn default() -> Path<B>

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

impl<B: Clone + Default + Display + PartialEq + Eq + PartialOrd + Ord + Hash> Display for Path<B>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<B: Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash + FromStr> From<&str> for Path<B>

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl<B: Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> From<Vec<B>> for Path<B>

source§

fn from(value: Vec<B>) -> Self

Converts to this type from the input type.
source§

impl<B: Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> FromIterator<B> for Path<B>

source§

fn from_iter<T: IntoIterator<Item = B>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<B: Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash + FromStr> FromStr for Path<B>

§

type Err = ParsePathError

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl<B: Hash + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> Hash for Path<B>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<N, B> Index<&Path<B>> for Tree<N, B>

§

type Output = N

The returned type after indexing.
source§

fn index(&self, index: &Path<B>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<B: Clone + Default + Ord + Hash> IntoIterator for Path<B>

§

type Item = B

The type of the elements being iterated over.
§

type IntoIter = IntoIter<B>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<B: Ord + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> Ord for Path<B>

source§

fn cmp(&self, other: &Path<B>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<B: PartialEq + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> PartialEq for Path<B>

source§

fn eq(&self, other: &Path<B>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<B: PartialOrd + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> PartialOrd for Path<B>

source§

fn partial_cmp(&self, other: &Path<B>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<B: Eq + Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> Eq for Path<B>

source§

impl<B: Clone + Default + PartialEq + Eq + PartialOrd + Ord + Hash> StructuralPartialEq for Path<B>

Auto Trait Implementations§

§

impl<B> Freeze for Path<B>

§

impl<B> RefUnwindSafe for Path<B>
where B: RefUnwindSafe,

§

impl<B> Send for Path<B>
where B: Send,

§

impl<B> Sync for Path<B>
where B: Sync,

§

impl<B> Unpin for Path<B>
where B: Unpin,

§

impl<B> UnwindSafe for Path<B>
where B: 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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.