Struct Tree

Source
pub struct Tree<Q, T>
where Q: PartialEq + Eq + Clone + Display + Debug + Hash + Ord, T: PartialEq + Eq + Clone,
{ /* private fields */ }
Expand description

A looping-enabled nested tree data structure for use in Parade. Keys must be globally unique, and there is no automatic balancing. There is no root node, and nodes can contain themselves or their ancestors. This probably makes “tree” an inaccurate term.

Implementations§

Source§

impl<Q, T> Tree<Q, T>
where Q: PartialEq + Eq + Clone + Display + Debug + Hash + Ord, T: PartialEq + Eq + Clone,

Source

pub fn new() -> Self

Creates a new empty Tree.

Source

pub fn get_parent(&self, key: &Q) -> Result<&Q, Error<Q>>

Fetches the parent key for the specified child key, if present.

§Errors

This method fails if the specified key is not present in the Tree.

Source

pub fn set_parent(&mut self, child: &Q, parent: Q) -> Result<(), Error<Q>>

Sets the parent key for the specified child key, if present.

§Errors

This method fails if either of the specified keys are not present in the Tree.

Source

pub fn rename(&mut self, from: &Q, to: Q) -> Result<(), Error<Q>>

Changes the key of the specified child to the provided one, if available. All parent-child relationships are preserved.

§Errors

This method fails if the specified from key is not present in the Tree, or if the to key is.

Source

pub fn add(&mut self, key: Q, node: Node<T, Q>) -> Result<(), Error<Q>>

Adds a new Node to the Tree at the specified key, if available.

§Errors

This method fails if the specified key is already present in the Tree.

Source

pub fn remove(&mut self, key: &Q, remove_children: bool) -> Result<T, Error<Q>>

Removes the Node at the specified key, if present, and returns its held value.

§Errors

This method fails if the specified key is not present in the Tree.

Source

pub fn get(&self, key: &Q) -> Result<&Node<T, Q>, Error<Q>>

Returns the Node at the specified key, if present.

§Errors

This method fails if the specified key is not present in the Tree.

Source

pub fn get_mut(&mut self, key: &Q) -> Result<&mut Node<T, Q>, Error<Q>>

Returns a mutable reference to the Node at the specified key, if present.

§Errors

This method fails if the specified key is not present in the Tree.

Source

pub fn get_from_parent( &self, key: &Q, parent: &Q, ) -> Result<Option<&Node<T, Q>>, Error<Q>>

Returns the Node at the specified key, if it is present and its parent matches the provided parent key. Returns None if the key is present but has a different parent.

§Errors

This method fails if the specified key is not present in the Tree.

Source

pub fn get_all(&self, keys: Vec<Q>) -> Result<BTreeMap<Q, Node<T, Q>>, Error<Q>>

Returns a BTreeMap containing the Nodes at the provided keys.

§Errors

This method fails if any of the provided keys are not present in the Tree.

Source

pub fn get_all_values(&self, keys: Vec<Q>) -> Result<BTreeMap<Q, T>, Error<Q>>

Returns a BTreeMap containing the values of the Nodes at the provided keys.

§Errors

This method fails if any of the provided keys are not present in the Tree.

Source

pub fn children(&self, key: &Q) -> Vec<Q>

Returns a Vec of the keys of all children of the specified parent key.

Source

pub fn siblings(&self, key: &Q, inclusive: bool) -> Result<Vec<Q>, Error<Q>>

Returns a Vec of the keys of all siblings of the specified key, optionally including the key itself.

§Errors

This method fails if the specified key is not present in the Tree.

Trait Implementations§

Source§

impl<Q, T> Clone for Tree<Q, T>
where Q: PartialEq + Eq + Clone + Display + Debug + Hash + Ord + Clone, T: PartialEq + Eq + Clone + Clone,

Source§

fn clone(&self) -> Tree<Q, T>

Returns a duplicate 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<Q, T> Debug for Tree<Q, T>
where Q: PartialEq + Eq + Clone + Display + Debug + Hash + Ord + Debug, T: PartialEq + Eq + Clone + Debug,

Source§

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

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

impl<Q, T> Default for Tree<Q, T>
where Q: PartialEq + Eq + Clone + Display + Debug + Hash + Ord, T: PartialEq + Eq + Clone,

Source§

fn default() -> Self

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

impl<'de, Q, T> Deserialize<'de> for Tree<Q, T>
where Q: PartialEq + Eq + Clone + Display + Debug + Hash + Ord + Deserialize<'de>, T: PartialEq + Eq + Clone + Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Q, T> Serialize for Tree<Q, T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<Q, T> Freeze for Tree<Q, T>

§

impl<Q, T> RefUnwindSafe for Tree<Q, T>

§

impl<Q, T> Send for Tree<Q, T>
where Q: Send, T: Send,

§

impl<Q, T> Sync for Tree<Q, T>
where Q: Sync, T: Sync,

§

impl<Q, T> Unpin for Tree<Q, T>
where Q: Unpin, T: Unpin,

§

impl<Q, T> UnwindSafe for Tree<Q, T>
where Q: UnwindSafe, T: 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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,