[][src]Struct atree::Node

pub struct Node<T> {
    pub data: T,
    // some fields omitted
}

A node holds data in the arena. Node<T> can be accessed by indexing Arena<T> with Token, using the get or get_mut methods of Arena<T>, or through tree iterators.

Fields

data: T

The data field.

Methods

impl<T> Node<T>[src]

pub fn token(&self) -> Token[src]

Returns the token of the given node.

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

Checks whether a given node is actually a leaf.

Important traits for AncestorTokens<'a, T>
pub fn ancestors_tokens<'a>(&self, arena: &'a Arena<T>) -> AncestorTokens<'a, T>[src]

Returns an iterator of tokens of ancestor nodes.

Examples:

use atree::Arena;
use atree::Node;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

let next_node_token = root_token.append(&mut arena, "Germanic");
let third_node_token = next_node_token.append(&mut arena, "English");

let third_node = &arena[third_node_token];
let mut ancestors_tokens = third_node.ancestors_tokens(&arena);

assert_eq!(ancestors_tokens.next(), Some(next_node_token));
assert_eq!(ancestors_tokens.next(), Some(root_token));
assert!(ancestors_tokens.next().is_none());

Important traits for PrecedingSiblingTokens<'a, T>
pub fn preceding_siblings_tokens<'a>(
    &self,
    arena: &'a Arena<T>
) -> PrecedingSiblingTokens<'a, T>
[src]

Returns an iterator of tokens of siblings preceding the current node.

Examples:

use atree::Arena;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

let first_child_token = root_token.append(&mut arena, "Germanic");
let second_child_token = root_token.append(&mut arena, "Romance");
let third_child_token = root_token.append(&mut arena, "Slavic");
root_token.append(&mut arena, "Hellenic");

let third_child = &arena[third_child_token];
let mut sibling_tokens = third_child.preceding_siblings_tokens(&arena);
assert_eq!(sibling_tokens.next(), Some(second_child_token));
assert_eq!(sibling_tokens.next(), Some(first_child_token));
assert!(sibling_tokens.next().is_none());

Important traits for FollowingSiblingTokens<'a, T>
pub fn following_siblings_tokens<'a>(
    &self,
    arena: &'a Arena<T>
) -> FollowingSiblingTokens<'a, T>
[src]

Returns an iterator of tokens of siblings following the current node.

Examples:

use atree::Arena;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

root_token.append(&mut arena, "Romance");
let second_child_token = root_token.append(&mut arena, "Germanic");
let third_child_token = root_token.append(&mut arena, "Slavic");
let fourth_child_token = root_token.append(&mut arena, "Hellenic");

let second_child = &arena[second_child_token];
let mut sibling_tokens = second_child.following_siblings_tokens(&arena);
assert_eq!(sibling_tokens.next(), Some(third_child_token));
assert_eq!(sibling_tokens.next(), Some(fourth_child_token));
assert!(sibling_tokens.next().is_none());

Important traits for ChildrenTokens<'a, T>
pub fn children_tokens<'a>(&self, arena: &'a Arena<T>) -> ChildrenTokens<'a, T>[src]

Returns an iterator of tokens of child nodes in the order of insertion.

Examples:

use atree::Arena;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

let first_child_token = root_token.append(&mut arena, "Romance");
let second_child_token = root_token.append(&mut arena, "Germanic");
let third_child_token = root_token.append(&mut arena, "Slavic");
let fourth_child_token = root_token.append(&mut arena, "Hellenic");

let root = &arena[root_token];
let mut children_tokens = root_token.children_tokens(&arena);
assert_eq!(children_tokens.next(), Some(first_child_token));
assert_eq!(children_tokens.next(), Some(second_child_token));
assert_eq!(children_tokens.next(), Some(third_child_token));
assert_eq!(children_tokens.next(), Some(fourth_child_token));
assert!(children_tokens.next().is_none());

Important traits for Ancestors<'a, T>
pub fn ancestors<'a>(&self, arena: &'a Arena<T>) -> Ancestors<'a, T>[src]

Returns an iterator of references of ancestor nodes.

Examples:

use atree::Arena;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

let next_node_token = root_token.append(&mut arena, "Germanic");
let third_node_token = next_node_token.append(&mut arena, "Swedish");

let third_node = &arena[third_node_token];
let mut ancestors = third_node.ancestors(&arena);

assert_eq!(ancestors.next().unwrap().data, "Germanic");
assert_eq!(ancestors.next().unwrap().data, "Indo-European");
assert!(ancestors.next().is_none());

Important traits for FollowingSiblings<'a, T>
pub fn following_siblings<'a>(
    &self,
    arena: &'a Arena<T>
) -> FollowingSiblings<'a, T>
[src]

Returns an iterator of references of sibling nodes following the current node.

Examples:

use atree::Arena;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

root_token.append(&mut arena, "Romance");
let second_child_token = root_token.append(&mut arena, "Germanic");
root_token.append(&mut arena, "Slavic");
root_token.append(&mut arena, "Hellenic");

let second_child = &arena[second_child_token];
let mut siblings = second_child_token.following_siblings(&arena);
assert_eq!(siblings.next().unwrap().data, "Slavic");
assert_eq!(siblings.next().unwrap().data, "Hellenic");
assert!(siblings.next().is_none());

Important traits for PrecedingSiblings<'a, T>
pub fn preceding_siblings<'a>(
    &self,
    arena: &'a Arena<T>
) -> PrecedingSiblings<'a, T>
[src]

Returns an iterator of references of sibling nodes preceding the current node.

Examples:

use atree::Arena;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

root_token.append(&mut arena, "Romance");
root_token.append(&mut arena, "Germanic");
let third_child_token = root_token.append(&mut arena, "Slavic");
root_token.append(&mut arena, "Celtic");

let third_child = &arena[third_child_token];
let mut siblings = third_child.preceding_siblings(&arena);
assert_eq!(siblings.next().unwrap().data, "Germanic");
assert_eq!(siblings.next().unwrap().data, "Romance");
assert!(siblings.next().is_none());

Important traits for Children<'a, T>
pub fn children<'a>(&self, arena: &'a Arena<T>) -> Children<'a, T>[src]

Returns an iterator of child node references in the order of insertion.

Examples:

use atree::Arena;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

let first_child_token = root_token.append(&mut arena, "Germanic");
let second_child_token = root_token.append(&mut arena, "Romance");
let third_child_token = root_token.append(&mut arena, "Slavic");
let fourth_child_token = root_token.append(&mut arena, "Celtic");

let root = &arena[root_token];
let mut children = root.children(&arena);
assert_eq!(children.next().unwrap().data, "Germanic");
assert_eq!(children.next().unwrap().data, "Romance");
assert_eq!(children.next().unwrap().data, "Slavic");
assert_eq!(children.next().unwrap().data, "Celtic");
assert!(children.next().is_none());

Important traits for SubtreeTokens<'a, T>
pub fn subtree_tokens<'a>(
    &self,
    arena: &'a Arena<T>,
    order: TraversalOrder
) -> SubtreeTokens<'a, T>
[src]

Returns an iterator of tokens of subtree nodes of the given node.

Examples:

use atree::Arena;
use atree::iter::TraversalOrder;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

let first_child = root_token.append(&mut arena, "Romance");
let second_child = root_token.append(&mut arena, "Germanic");
let third_child = root_token.append(&mut arena, "Slavic");
let first_grandchild = second_child.append(&mut arena, "English");
let second_grandchild = second_child.append(&mut arena, "Icelandic");
let fourth_child = root_token.append(&mut arena, "Celtic");

let root = &arena[root_token];
let mut subtree = root.subtree_tokens(&arena, TraversalOrder::Pre);
assert_eq!(subtree.next(), Some(root_token));
assert_eq!(subtree.next(), Some(first_child));
assert_eq!(subtree.next(), Some(second_child));
assert_eq!(subtree.next(), Some(first_grandchild));
assert_eq!(subtree.next(), Some(second_grandchild));
assert_eq!(subtree.next(), Some(third_child));
assert_eq!(subtree.next(), Some(fourth_child));
assert!(subtree.next().is_none());

let second_child_node = &arena[second_child];
let mut subtree = second_child_node.subtree_tokens(&arena, TraversalOrder::Pre);
assert_eq!(subtree.next(), Some(second_child));
assert_eq!(subtree.next(), Some(first_grandchild));
assert_eq!(subtree.next(), Some(second_grandchild));
assert!(subtree.next().is_none());

Important traits for Subtree<'a, T>
pub fn subtree<'a>(
    &self,
    arena: &'a Arena<T>,
    order: TraversalOrder
) -> Subtree<'a, T>
[src]

Returns an iterator of references of subtree nodes of the given node.

Examples:

use atree::Arena;
use atree::iter::TraversalOrder;

let root_data = "Indo-European";
let (mut arena, root_token) = Arena::with_data(root_data);

root_token.append(&mut arena, "Romance");
root_token.append(&mut arena, "Germanic");
let third_child = root_token.append(&mut arena, "Slavic");
root_token.append(&mut arena, "Celtic");
third_child.append(&mut arena, "Polish");
third_child.append(&mut arena, "Slovakian");

let root = &arena[root_token];
let mut subtree = root.subtree(&arena, TraversalOrder::Pre);
assert_eq!(subtree.next().unwrap().data, "Indo-European");
assert_eq!(subtree.next().unwrap().data, "Romance");
assert_eq!(subtree.next().unwrap().data, "Germanic");
assert_eq!(subtree.next().unwrap().data, "Slavic");
assert_eq!(subtree.next().unwrap().data, "Polish");
assert_eq!(subtree.next().unwrap().data, "Slovakian");
assert_eq!(subtree.next().unwrap().data, "Celtic");
assert!(subtree.next().is_none());

Trait Implementations

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

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

Auto Trait Implementations

impl<T> RefUnwindSafe for Node<T> where
    T: RefUnwindSafe

impl<T> Send for Node<T> where
    T: Send

impl<T> Sync for Node<T> where
    T: Sync

impl<T> Unpin for Node<T> where
    T: Unpin

impl<T> UnwindSafe for Node<T> where
    T: 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<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.