[][src]Struct lineartree::Tree

pub struct Tree<T> { /* fields omitted */ }

Implementations

impl<T> Tree<T>[src]

Represent a tree structure.

This structure is the core of the library and will own all data in the tree. All functions for creating, manipulating and removing nodes, as well as add children, and perform various types of iteration are methods of this struct.

pub fn new() -> Self[src]

Create new empty tree structure.

Returns: Tree struct.

pub fn root(&mut self, content: T) -> Result<NodeRef, TreeError>[src]

Create a root node.

There can be only one root node in a tree, and calling this function twice will result in an error. Trees without root nodes are valid, but you won't be able to use some functionality like iteration over all nodes in a tree.

Arguments:

  • content - The item to be set as content of the root node.

Returns: A NodeRef object referencing the created node.

pub fn node(&mut self, content: T) -> NodeRef[src]

Create a node.

Arguments:

  • content - The item to be set as content of the node.

Returns: A result containing a NodeRef object referencing the created node.

pub fn child_node(
    &mut self,
    parent: NodeRef,
    content: T
) -> Result<NodeRef, TreeError>
[src]

Create a node child on another.

Arguments:

  • parent_ref - NodeRef of the parent node.
  • content - The item to be set as content of the node.

Returns: A NodeRef object referencing the created node.

pub fn remove(&mut self, node_ref: NodeRef) -> Result<(), TreeError>[src]

Remove a node from the tree.

The removed node will not reduce the amount of memory used by the tree, nor resize the underying vector so that other node references won't be invalidated.

Arguments:

  • node_ref - NodeRef object indicating which node to remove.

Returns: A result indicating whether the node was successfully removed. Returns an error if node_ref is invalid or if it was already removed.

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

Get the number of nodes in the tree.

This is not the same as the space used by the vector implementation if some nodes where removed.

pub fn get(&self, node_ref: NodeRef) -> Option<&T>[src]

Get immutable reference to the node content.

Arguments:

  • node_ref - NodeRef object indicating which node content to retrieve.

Returns: Reference to the object contained in the node or None if the node_ref is invalid.

pub fn get_mut(&mut self, node_ref: NodeRef) -> Option<&mut T>[src]

Get mutable reference to the node content.

Arguments:

  • node_ref - NodeRef object indicating which node content to retrieve.

Returns: Mutable reference to the object contained in the node or None if the node_ref is invalid.

pub fn append_child(
    &mut self,
    parent_ref: NodeRef,
    child_ref: NodeRef
) -> Result<(), TreeError>
[src]

Add child node to a node.

Arguments:

  • parent_ref - NodeRef of the parent node.
  • child_ref - NodeRef of the child node.

Returns: Result indicating whether the operations was successful. Returns an error if one of the node references is invalid.

pub fn append_children(
    &mut self,
    parent_ref: NodeRef,
    children_refs: &[NodeRef]
) -> Result<(), TreeError>
[src]

Add children nodes to a node.

Arguments:

  • parent_ref - NodeRef of of the parent node.
  • children_refs - Slice of NodeRef for the child nodes.

Returns: Result indicating whether the operations was successful. Returns an error if one of the node references is invalid.

pub fn get_children(
    &self,
    parent_ref: NodeRef
) -> Result<Iter<'_, NodeRef>, TreeError>
[src]

Get iterator returning references to a node's children.

Arguments:

  • parent_ref - NodeRef of the parent node.

Returns: Iterator returning node references to the children. Returns error if the parent reference is invalid.

pub fn get_parent(
    &self,
    child_ref: NodeRef
) -> Result<Option<NodeRef>, TreeError>
[src]

Get reference to the parent node.

Arguments:

  • child_ref - NodeRef of the child node.

Returns: A reference to the parent node or None if no parent exists. Returns error if the parent does not exist.

pub fn depth_first_of(
    &self,
    node_ref: NodeRef,
    include_start: bool
) -> Result<DepthFirstIterator<'_, T>, TreeError>
[src]

Get an iterator traversing the node and all child nodes in depth-first order.

Arguments:

  • node_ref - NodeRef of the starting node.
  • include_start - If true, iteration starts with the starting node instead of with the first thereof.

Returns: An iterator returning the node references to the child nodes in depth-first order. Returns error if the start node does not exist.

pub fn depth_first(
    &self,
    include_root: bool
) -> Result<DepthFirstIterator<'_, T>, TreeError>
[src]

Get an iterator traversing all nodes in the tree in a depth-first order.

Arguments:

  • include_root - If true, iteration starts with the root node instead of with the first thereof.

Returns: An iterator returning the node references to the nodes in depth-first order. Returns error if no root node exist.

Trait Implementations

impl<T: Clone> Clone for Tree<T>[src]

impl<T: Debug> Debug for Tree<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Tree<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for Tree<T> where
    T: Send
[src]

impl<T> Sync for Tree<T> where
    T: Sync
[src]

impl<T> Unpin for Tree<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for Tree<T> where
    T: UnwindSafe
[src]

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