pub struct Node<T> {
pub data: T,
/* private fields */
}Expand description
Fields§
§data: TThe data field.
Implementations§
Source§impl<T> Node<T>
impl<T> Node<T>
Sourcepub fn ancestors_tokens<'a>(&self, arena: &'a Arena<T>) -> AncestorTokens<'a, T> ⓘ
pub fn ancestors_tokens<'a>(&self, arena: &'a Arena<T>) -> AncestorTokens<'a, T> ⓘ
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());Sourcepub fn preceding_siblings_tokens<'a>(
&self,
arena: &'a Arena<T>,
) -> PrecedingSiblingTokens<'a, T> ⓘ
pub fn preceding_siblings_tokens<'a>( &self, arena: &'a Arena<T>, ) -> PrecedingSiblingTokens<'a, T> ⓘ
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());Sourcepub fn following_siblings_tokens<'a>(
&self,
arena: &'a Arena<T>,
) -> FollowingSiblingTokens<'a, T> ⓘ
pub fn following_siblings_tokens<'a>( &self, arena: &'a Arena<T>, ) -> FollowingSiblingTokens<'a, T> ⓘ
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());Sourcepub fn children_tokens<'a>(&self, arena: &'a Arena<T>) -> ChildrenTokens<'a, T> ⓘ
pub fn children_tokens<'a>(&self, arena: &'a Arena<T>) -> ChildrenTokens<'a, T> ⓘ
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());Sourcepub fn ancestors<'a>(&self, arena: &'a Arena<T>) -> Ancestors<'a, T> ⓘ
pub fn ancestors<'a>(&self, arena: &'a Arena<T>) -> Ancestors<'a, T> ⓘ
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());Sourcepub fn following_siblings<'a>(
&self,
arena: &'a Arena<T>,
) -> FollowingSiblings<'a, T> ⓘ
pub fn following_siblings<'a>( &self, arena: &'a Arena<T>, ) -> FollowingSiblings<'a, T> ⓘ
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());Sourcepub fn preceding_siblings<'a>(
&self,
arena: &'a Arena<T>,
) -> PrecedingSiblings<'a, T> ⓘ
pub fn preceding_siblings<'a>( &self, arena: &'a Arena<T>, ) -> PrecedingSiblings<'a, T> ⓘ
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());Sourcepub fn children<'a>(&self, arena: &'a Arena<T>) -> Children<'a, T> ⓘ
pub fn children<'a>(&self, arena: &'a Arena<T>) -> Children<'a, T> ⓘ
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());Sourcepub fn subtree_tokens<'a>(
&self,
arena: &'a Arena<T>,
order: TraversalOrder,
) -> SubtreeTokens<'a, T> ⓘ
pub fn subtree_tokens<'a>( &self, arena: &'a Arena<T>, order: TraversalOrder, ) -> SubtreeTokens<'a, T> ⓘ
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());Sourcepub fn subtree<'a>(
&self,
arena: &'a Arena<T>,
order: TraversalOrder,
) -> Subtree<'a, T> ⓘ
pub fn subtree<'a>( &self, arena: &'a Arena<T>, order: TraversalOrder, ) -> Subtree<'a, T> ⓘ
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§
Auto Trait Implementations§
impl<T> Freeze for Node<T>where
T: Freeze,
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more