Enum rosary::RoseTree[][src]

pub enum RoseTree<V> {
    Leaf(V),
    Branch(V, Vec<RoseTree<V>>),
}

Variants

Leaf(V)

A simple (and almost certainly terribly inefficient) Rose Tree implementation. A dead end node, single value.

Branch(V, Vec<RoseTree<V>>)

A branch has a head value, and then all its child values.

Implementations

impl<V> RoseTree<V>[src]

pub fn leaf(val: V) -> Self[src]

Constructors, because I don’t know how to make From do this for me.

pub fn branch<I: Iterator<Item = V>>(val: V, children: I) -> Self[src]

pub fn ref_tree(&self) -> RoseTree<&V>[src]

Creates a tree of the same structure as self where every node is a reference to the corresponding node in the owning tree.

pub fn is_leaf(&self) -> bool[src]

These three check if a RoseTree is of a given variant.

pub fn is_branch(&self) -> bool[src]

pub fn size(&self) -> usize[src]

Calculates the number of nodes in the tree.

pub fn head(&self) -> Option<&V>[src]

Retrieves a reference to the head of the tree.

pub fn head_mut(&mut self) -> Option<&mut V>[src]

pub fn children(&self) -> Option<&Vec<RoseTree<V>>>[src]

Gets the children of a branch directly, if it is a branch.

pub fn children_mut(&mut self) -> Option<&mut Vec<RoseTree<V>>>[src]

pub fn swap_head(self, new_head: V) -> Self[src]

Swaps out the head-most value of the tree with the provided one.

pub fn add_child(self, child: V) -> Self[src]

Adds a child to specifically a Branch node.

pub fn map_head(self, head_fn: fn(_: V) -> V) -> Self[src]

pub fn map_leaves(self, child_fn: fn(_: V) -> V) -> Self[src]

Map over only the leaves of the tree.

pub fn map<U>(&self, func: fn(_: &V) -> U) -> RoseTree<U>[src]

Map over the whole tree.

pub fn map_into<U>(self, func: fn(_: V) -> U) -> RoseTree<U>[src]

pub fn depth_map<A: Clone, U>(
    &self,
    initial: A,
    func: fn(_: A, _: &V) -> (A, U)
) -> RoseTree<U>
[src]

Maps over the tree, where each child of the same parent receives the same accumulator value as a function argument. Add more variants of this for different argument mutabilities maybe?

pub fn filter<F: Fn(&V) -> bool>(self, func: F) -> Option<Self>[src]

Removes all values from the tree which don’t satisfy the predicate. In the case of branches, if the head of the branch does not satisfy the predicate, both it and all its children are removed.

pub fn preorder_iter<'a>(&'a self) -> PreorderRoseIter<'_, V>

Notable traits for PreorderRoseIter<'a, T>

impl<'a, T: Debug> Iterator for PreorderRoseIter<'a, T> type Item = &'a T;
[src]

Trait Implementations

impl<V: Clone> Clone for RoseTree<V>[src]

impl<V: Debug> Debug for RoseTree<V>[src]

impl<V: Display> Display for RoseTree<V>[src]

impl<V: Eq> Eq for RoseTree<V>[src]

impl<V, I: IntoIterator<Item = V>> From<(V, I)> for RoseTree<V>[src]

fn from((head, child_collection): (V, I)) -> RoseTree<V>[src]

Convenience to make wrapping anything in a Branch nicer(I know, shocking).

impl<V> From<V> for RoseTree<V>[src]

fn from(val: V) -> Self[src]

Convenience function to make wrapping anything in a leaf nicer.

impl<V: PartialEq> PartialEq<RoseTree<V>> for RoseTree<V>[src]

fn eq(&self, other: &Self) -> bool[src]

It’d be really nice to be able to check equality of variants independently of the values within the variants, but I have no idea how or if that’s possible.

impl<V> StructuralEq for RoseTree<V>[src]

impl<T: Display> TreeFormat for RoseTree<T>[src]

If you’re a RoseTree, you get TreeFormat for free so long as T can be printed. If printing T involves printing newlines, don’t. It’ll get weird.

Auto Trait Implementations

impl<V> RefUnwindSafe for RoseTree<V> where
    V: RefUnwindSafe

impl<V> Send for RoseTree<V> where
    V: Send

impl<V> Sync for RoseTree<V> where
    V: Sync

impl<V> Unpin for RoseTree<V> where
    V: Unpin

impl<V> UnwindSafe for RoseTree<V> where
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.