[−][src]Struct atree::Token
A Token
is a handle to a node in the arena.
Methods
impl Token
[src]
pub fn is_leaf<T>(self, arena: &Arena<T>) -> bool
[src]
Checks whether a given node is actually a leaf.
Panics:
Panics if the token does not correspond to a node in the arena.
pub fn append<T>(self, arena: &mut Arena<T>, data: T) -> Token
[src]
Creates a new node with the given data and append to the given node.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; 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"); next_node_token.append(&mut arena, "Romance"); let mut subtree = root_token.subtree(&arena, TraversalOrder::Pre); assert_eq!(subtree.next().unwrap().data, "Indo-European"); assert_eq!(subtree.next().unwrap().data, "Germanic"); assert_eq!(subtree.next().unwrap().data, "Romance");
pub fn insert_before<T>(self, arena: &mut Arena<T>, data: T) -> Token
[src]
Creates a new node with the given data and sets as the previous sibling of the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; let root_data = "Indo-European"; let (mut arena, root_token) = Arena::with_data(root_data); let child2 = root_token.append(&mut arena, "Germanic"); let child4 = root_token.append(&mut arena, "Slavic"); child2.append(&mut arena, "English"); // insert in between children 2 and 4 let child3 = child4.insert_before(&mut arena, "Romance"); // insert before child 2 let child1 = child2.insert_before(&mut arena, "Celtic"); let subtree: Vec<_> = root_token.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data) .collect(); assert_eq!(&["Indo-European", "Celtic", "Germanic", "English", "Romance", "Slavic"], &subtree[..]);
pub fn insert_node_after<T>(
self,
arena: &mut Arena<T>,
other: Token
) -> Result<(), Error>
[src]
self,
arena: &mut Arena<T>,
other: Token
) -> Result<(), Error>
Set a node in the arena as the next sibling of the given node. Returns error if the "other node" is not a root node of a tree (as in it already has a parent and/or siblings).
Note: for performance reasons, this operation does not check whether the "self" node is in fact a descendant of the other tree. A cyclic graph may result.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; // root node that we will attach subtrees to let root_data = "Indo-European"; let (mut arena, root) = Arena::with_data(root_data); let germanic = root.append(&mut arena, "Germanic"); let scots = germanic.append(&mut arena, "German"); let english = germanic.append(&mut arena, "English"); let romance = arena.new_node("Romance"); let french = romance.append(&mut arena, "French"); let spanish = romance.append(&mut arena, "Spanish"); germanic.insert_node_after(&mut arena, romance); let mut iter = root.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data); assert_eq!(iter.next(), Some("Indo-European")); assert_eq!(iter.next(), Some("Germanic")); assert_eq!(iter.next(), Some("German")); assert_eq!(iter.next(), Some("English")); assert_eq!(iter.next(), Some("Romance")); assert_eq!(iter.next(), Some("French")); assert_eq!(iter.next(), Some("Spanish")); assert!(iter.next().is_none())
pub fn insert_node_before<T>(
self,
arena: &mut Arena<T>,
other: Token
) -> Result<(), Error>
[src]
self,
arena: &mut Arena<T>,
other: Token
) -> Result<(), Error>
Set a node in the arena as the previous sibling of the given node. Returns error if the "other node" is not a root node of a tree (as in it already has a parent and/or siblings).
Note: for performance reasons, this operation does not check whether the "self" node is in fact a descendant of the other tree. A cyclic graph may result.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; // root node that we will attach subtrees to let root_data = "Indo-European"; let (mut arena, root) = Arena::with_data(root_data); let germanic = root.append(&mut arena, "Germanic"); let scots = germanic.append(&mut arena, "German"); let english = germanic.append(&mut arena, "English"); let romance = arena.new_node("Romance"); let french = romance.append(&mut arena, "French"); let spanish = romance.append(&mut arena, "Spanish"); germanic.insert_node_before(&mut arena, romance); let mut iter = root.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data); assert_eq!(iter.next(), Some("Indo-European")); assert_eq!(iter.next(), Some("Romance")); assert_eq!(iter.next(), Some("French")); assert_eq!(iter.next(), Some("Spanish")); assert_eq!(iter.next(), Some("Germanic")); assert_eq!(iter.next(), Some("German")); assert_eq!(iter.next(), Some("English")); assert!(iter.next().is_none())
pub fn insert_after<T>(self, arena: &mut Arena<T>, data: T) -> Token
[src]
Creates a new node with the given data and sets as the next sibling of the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; let root_data = "Indo-European"; let (mut arena, root_token) = Arena::with_data(root_data); let child1 = root_token.append(&mut arena, "Romance"); let child3 = root_token.append(&mut arena, "Germanic"); child1.append(&mut arena, "French"); // insert betwern children 1 and 4 let child2 = child1.insert_after(&mut arena, "Celtic"); // insert after child 3 child3.insert_after(&mut arena, "Slavic"); let subtree: Vec<_> = root_token.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data) .collect(); assert_eq!(&["Indo-European", "Romance", "French", "Celtic", "Germanic", "Slavic"], &subtree[..]);
pub fn append_node<T>(
self,
arena: &mut Arena<T>,
other: Self
) -> Result<(), Error>
[src]
self,
arena: &mut Arena<T>,
other: Self
) -> Result<(), Error>
Attaches a different tree in the arena to a node. Returns error if the
"root node" of the other tree is not really a root node (as in it
already has a parent and/or siblings). To attach a tree from a different
arena, use copy_and_append_subtree
instead.
Note: for performance reasons, this operation does not check whether the "self" node is in fact a descendant of the other tree. A cyclic graph may result.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; // root node that we will attach subtrees to let root_data = "Indo-European"; let (mut arena, root) = Arena::with_data(root_data); // the Germanic branch let germanic = arena.new_node("Germanic"); let west = germanic.append(&mut arena, "West"); let scots = west.append(&mut arena, "Scots"); let english = west.append(&mut arena, "English"); // the Romance branch let romance = arena.new_node("Romance"); let french = romance.append(&mut arena, "French"); let italian = romance.append(&mut arena, "Italian"); // attach subtrees root.append_node(&mut arena, romance).unwrap(); root.append_node(&mut arena, germanic).unwrap(); let mut iter = root.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data); assert_eq!(iter.next(), Some("Indo-European")); assert_eq!(iter.next(), Some("Romance")); assert_eq!(iter.next(), Some("French")); assert_eq!(iter.next(), Some("Italian")); assert_eq!(iter.next(), Some("Germanic")); assert_eq!(iter.next(), Some("West")); assert_eq!(iter.next(), Some("Scots")); assert_eq!(iter.next(), Some("English")); assert!(iter.next().is_none())
pub fn detach<T>(self, arena: &mut Arena<T>)
[src]
Detaches the given node and its descendants into its own tree while
keeping it in the same arena. To detach and allocate the subtree into its
own arena, use split_at
instead.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; // root node that we will attach subtrees to let root_data = "Indo-European"; let (mut arena, root) = Arena::with_data(root_data); // the Germanic branch let germanic = root.append(&mut arena, "Germanic"); let west = germanic.append(&mut arena, "West"); let scots = west.append(&mut arena, "Scots"); let english = west.append(&mut arena, "English"); // detach the west branch from the main tree west.detach(&mut arena); // the west branch is gone from the original tree let mut iter = root.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data); assert_eq!(iter.next(), Some("Indo-European")); assert_eq!(iter.next(), Some("Germanic")); assert!(iter.next().is_none()); // it exists on its own let mut iter = west.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data); assert_eq!(iter.next(), Some("West")); assert_eq!(iter.next(), Some("Scots")); assert_eq!(iter.next(), Some("English")); assert!(iter.next().is_none());
pub fn replace_node<T>(
self,
arena: &mut Arena<T>,
other: Token
) -> Result<(), Error>
[src]
self,
arena: &mut Arena<T>,
other: Token
) -> Result<(), Error>
Replace the subtree of self with the subtree of other. Does not remove self or its descendants but simply makes it a standalone tree within the arena.
Note: for performance reasons, this operation does not check whether the "other" node is in fact a descendant of the parent tree of self. A cyclic graph may result.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; // root node that we will attach subtrees to let root_data = "Indo-European"; let (mut arena, root) = Arena::with_data(root_data); // the Germanic branch let germanic = root.append(&mut arena, "Germanic"); let west = germanic.append(&mut arena, "West"); let scots = west.append(&mut arena, "Scots"); let english = west.append(&mut arena, "English"); // the slavic branch let slavic = root.append(&mut arena, "Slavic"); let polish = slavic.append(&mut arena, "Polish"); let russian = slavic.append(&mut arena, "Russian"); // the Romance branch let romance = arena.new_node("Romance"); let french = romance.append(&mut arena, "French"); let italian = romance.append(&mut arena, "Italian"); // replace_node germanic with romance germanic.replace_node(&mut arena, romance).unwrap(); let mut iter = root.subtree(&arena, TraversalOrder::Pre) .map(|x| x.data); assert_eq!(iter.next(), Some("Indo-European")); assert_eq!(iter.next(), Some("Romance")); assert_eq!(iter.next(), Some("French")); assert_eq!(iter.next(), Some("Italian")); assert_eq!(iter.next(), Some("Slavic")); assert_eq!(iter.next(), Some("Polish")); assert_eq!(iter.next(), Some("Russian")); assert!(iter.next().is_none());
ⓘImportant traits for AncestorTokens<'a, T>pub fn ancestors_tokens<'a, T>(
self,
arena: &'a Arena<T>
) -> AncestorTokens<'a, T>
[src]
self,
arena: &'a Arena<T>
) -> AncestorTokens<'a, T>
Returns an iterator of tokens of ancestor nodes.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; let root_data = "Indo-European"; let (mut arena, root_token) = Arena::with_data(root_data); let child_token = root_token.append(&mut arena, "Germanic"); let grandchild_token = child_token.append(&mut arena, "English"); let mut ancestors_tokens = grandchild_token.ancestors_tokens(&arena); assert_eq!(ancestors_tokens.next(), Some(child_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, T>(
self,
arena: &'a Arena<T>
) -> PrecedingSiblingTokens<'a, T>
[src]
self,
arena: &'a Arena<T>
) -> PrecedingSiblingTokens<'a, T>
Returns an iterator of tokens of siblings preceding the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
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 mut sibling_tokens = third_child_token.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, T>(
self,
arena: &'a Arena<T>
) -> FollowingSiblingTokens<'a, T>
[src]
self,
arena: &'a Arena<T>
) -> FollowingSiblingTokens<'a, T>
Returns an iterator of tokens of siblings following the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
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 mut sibling_tokens = second_child_token.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, T>(
self,
arena: &'a Arena<T>
) -> ChildrenTokens<'a, T>
[src]
self,
arena: &'a Arena<T>
) -> ChildrenTokens<'a, T>
Returns an iterator of tokens of child nodes in the order of insertion.
Panics:
Panics if the token does not correspond to a node in the arena.
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 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, T>(self, arena: &'a Arena<T>) -> Ancestors<'a, T>
[src]
Returns an iterator of references of ancestor nodes.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; let root_data = "Indo-European"; let (mut arena, root_token) = Arena::with_data(root_data); let child_token = root_token.append(&mut arena, "Germanic"); let grandchild_token = child_token.append(&mut arena, "Swedish"); let mut ancestors = grandchild_token.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 PrecedingSiblings<'a, T>pub fn preceding_siblings<'a, T>(
self,
arena: &'a Arena<T>
) -> PrecedingSiblings<'a, T>
[src]
self,
arena: &'a Arena<T>
) -> PrecedingSiblings<'a, T>
Returns an iterator of references of sibling nodes preceding the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
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 mut siblings = third_child_token.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 FollowingSiblings<'a, T>pub fn following_siblings<'a, T>(
self,
arena: &'a Arena<T>
) -> FollowingSiblings<'a, T>
[src]
self,
arena: &'a Arena<T>
) -> FollowingSiblings<'a, T>
Returns an iterator of references of sibling nodes following the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
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 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 Children<'a, T>pub fn children<'a, T>(self, arena: &'a Arena<T>) -> Children<'a, T>
[src]
Returns an iterator of child node references in the order of insertion.
Panics:
Panics if the token does not correspond to a node in the arena.
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 mut children = root_token.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 AncestorsMut<'a, T>pub fn ancestors_mut<'a, T>(
self,
arena: &'a mut Arena<T>
) -> AncestorsMut<'a, T>
[src]
self,
arena: &'a mut Arena<T>
) -> AncestorsMut<'a, T>
Returns an iterator of mutable ancestor node references.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; let root_data = 1usize; let (mut arena, root_token) = Arena::with_data(root_data); let child_token = root_token.append(&mut arena, 2usize); let grandchild_token = child_token.append(&mut arena, 3usize); let great_grandchild_token = grandchild_token.append(&mut arena, 4usize); let ggreat_grandchild_token = great_grandchild_token.append(&mut arena, 5usize); for x in ggreat_grandchild_token.ancestors_mut(&mut arena) { x.data += 2; } let mut ancestors = ggreat_grandchild_token.ancestors(&arena); assert_eq!(ancestors.next().unwrap().data, 6usize); assert_eq!(ancestors.next().unwrap().data, 5usize); assert_eq!(ancestors.next().unwrap().data, 4usize); assert_eq!(ancestors.next().unwrap().data, 3usize); assert!(ancestors.next().is_none());
ⓘImportant traits for FollowingSiblingsMut<'a, T>pub fn following_siblings_mut<'a, T>(
self,
arena: &'a mut Arena<T>
) -> FollowingSiblingsMut<'a, T>
[src]
self,
arena: &'a mut Arena<T>
) -> FollowingSiblingsMut<'a, T>
Returns an iterator of mutable references of sibling nodes that follow the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; let root_data = 1usize; let (mut arena, root_token) = Arena::with_data(root_data); root_token.append(&mut arena, 2usize); let second_child_token = root_token.append(&mut arena, 3usize); root_token.append(&mut arena, 4usize); root_token.append(&mut arena, 5usize); for x in second_child_token.following_siblings_mut(&mut arena) { x.data += 2; } let mut children = root_token.children(&arena); assert_eq!(children.next().unwrap().data, 2usize); assert_eq!(children.next().unwrap().data, 3usize); assert_eq!(children.next().unwrap().data, 6usize); assert_eq!(children.next().unwrap().data, 7usize); assert!(children.next().is_none());
ⓘImportant traits for PrecedingSiblingsMut<'a, T>pub fn preceding_siblings_mut<'a, T>(
self,
arena: &'a mut Arena<T>
) -> PrecedingSiblingsMut<'a, T>
[src]
self,
arena: &'a mut Arena<T>
) -> PrecedingSiblingsMut<'a, T>
Returns an iterator of mutable references of sibling nodes that precede the current node.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; let root_data = 1usize; let (mut arena, root_token) = Arena::with_data(root_data); root_token.append(&mut arena, 2usize); root_token.append(&mut arena, 3usize); root_token.append(&mut arena, 4usize); let fourth_child_token = root_token.append(&mut arena, 5usize); for x in fourth_child_token.preceding_siblings_mut(&mut arena) { x.data += 5; } let mut children = root_token.children(&arena); assert_eq!(children.next().unwrap().data, 7usize); assert_eq!(children.next().unwrap().data, 8usize); assert_eq!(children.next().unwrap().data, 9usize); assert_eq!(children.next().unwrap().data, 5usize); assert!(children.next().is_none());
ⓘImportant traits for ChildrenMut<'a, T>pub fn children_mut<'a, T>(self, arena: &'a mut Arena<T>) -> ChildrenMut<'a, T>
[src]
Returns an iterator of mutable references of child nodes in the order of insertion.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; let root_data = 1usize; let (mut arena, root_token) = Arena::with_data(root_data); root_token.append(&mut arena, 2usize); root_token.append(&mut arena, 3usize); let third_child_token = root_token.append(&mut arena, 4usize); root_token.append(&mut arena, 5usize); let grandchild = third_child_token.append(&mut arena, 10usize); for x in root_token.children_mut(&mut arena) { x.data += 10; } let mut children = root_token.children(&arena); assert_eq!(children.next().unwrap().data, 12); assert_eq!(children.next().unwrap().data, 13); assert_eq!(children.next().unwrap().data, 14); assert_eq!(children.next().unwrap().data, 15); assert_eq!(arena.get(grandchild).unwrap().data, 10); assert!(children.next().is_none());
ⓘImportant traits for SubtreeTokens<'a, T>pub fn subtree_tokens<'a, T>(
self,
arena: &'a Arena<T>,
order: TraversalOrder
) -> SubtreeTokens<'a, T>
[src]
self,
arena: &'a Arena<T>,
order: TraversalOrder
) -> SubtreeTokens<'a, T>
Returns an iterator of tokens of subtree nodes of the given node.
Panics:
Panics if the token does not correspond to a node in the arena.
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 mut subtree = root_token.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 mut subtree = second_grandchild.subtree_tokens(&arena, TraversalOrder::Pre); assert_eq!(subtree.next(), Some(second_grandchild)); assert!(subtree.next().is_none());
ⓘImportant traits for Subtree<'a, T>pub fn subtree<'a, T>(
self,
arena: &'a Arena<T>,
order: TraversalOrder
) -> Subtree<'a, T>
[src]
self,
arena: &'a Arena<T>,
order: TraversalOrder
) -> Subtree<'a, T>
Returns an iterator of references of subtree nodes of the given node.
Panics:
Panics if the token does not correspond to a node in the arena.
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 mut subtree = root_token.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());
ⓘImportant traits for SubtreeMut<'a, T>pub fn subtree_mut<'a, T>(
self,
arena: &'a mut Arena<T>,
order: TraversalOrder
) -> SubtreeMut<'a, T>
[src]
self,
arena: &'a mut Arena<T>,
order: TraversalOrder
) -> SubtreeMut<'a, T>
Returns an iterator of mutable references of subtree nodes of the given node.
Panics:
Panics if the token does not correspond to a node in the arena.
Examples:
use atree::Arena; use atree::iter::TraversalOrder; let root_data = 1usize; let (mut arena, root_token) = Arena::with_data(root_data); root_token.append(&mut arena, 2usize); root_token.append(&mut arena, 3usize); let third_child = root_token.append(&mut arena, 4usize); root_token.append(&mut arena, 5usize); third_child.append(&mut arena, 10usize); third_child.append(&mut arena, 20usize); for x in root_token.subtree_mut(&mut arena, TraversalOrder::Pre) { x.data += 100; } let mut subtree = root_token.subtree(&arena, TraversalOrder::Pre); assert_eq!(subtree.next().unwrap().data, 101); assert_eq!(subtree.next().unwrap().data, 102); assert_eq!(subtree.next().unwrap().data, 103); assert_eq!(subtree.next().unwrap().data, 104); assert_eq!(subtree.next().unwrap().data, 110); assert_eq!(subtree.next().unwrap().data, 120); assert_eq!(subtree.next().unwrap().data, 105); assert!(subtree.next().is_none());
Trait Implementations
impl Clone for Token
[src]
impl Copy for Token
[src]
impl Debug for Token
[src]
impl Eq for Token
[src]
impl Hash for Token
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Index<Token> for Arena<T>
[src]
type Output = Node<T>
The returned type after indexing.
fn index(&self, index: Token) -> &Self::Output
[src]
impl<T> IndexMut<Token> for Arena<T>
[src]
impl PartialEq<Token> for Token
[src]
impl StructuralEq for Token
[src]
impl StructuralPartialEq for Token
[src]
Auto Trait Implementations
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnwindSafe for Token
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,