pub struct Node<T>(/* private fields */);
Expand description
A reference to a node holding a value of type T
. Nodes form a tree.
Internally, this uses reference counting for lifetime tracking
and std::cell::RefCell
for interior mutability.
Note: Cloning a Node
only increments a reference count. It does not copy the data.
Implementations§
source§impl<T> Node<T>
impl<T> Node<T>
sourcepub fn parent(&self) -> Option<Node<T>>
pub fn parent(&self) -> Option<Node<T>>
Returns a parent node, unless this node is the root of the tree.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn first_child(&self) -> Option<Node<T>>
pub fn first_child(&self) -> Option<Node<T>>
Returns a first child of this node, unless it has no child.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn last_child(&self) -> Option<Node<T>>
pub fn last_child(&self) -> Option<Node<T>>
Returns a last child of this node, unless it has no child.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn previous_sibling(&self) -> Option<Node<T>>
pub fn previous_sibling(&self) -> Option<Node<T>>
Returns the previous sibling of this node, unless it is a first child.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn next_sibling(&self) -> Option<Node<T>>
pub fn next_sibling(&self) -> Option<Node<T>>
Returns the next sibling of this node, unless it is a last child.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
Returns a shared reference to this node’s data.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn borrow_mut(&self) -> RefMut<'_, T>
pub fn borrow_mut(&self) -> RefMut<'_, T>
Returns a unique/mutable reference to this node’s data.
Panics
Panics if the node is currently borrowed.
sourcepub fn ancestors(&self) -> Ancestors<T> ⓘ
pub fn ancestors(&self) -> Ancestors<T> ⓘ
Returns an iterator of nodes to this node and its ancestors.
Includes the current node.
sourcepub fn preceding_siblings(&self) -> PrecedingSiblings<T> ⓘ
pub fn preceding_siblings(&self) -> PrecedingSiblings<T> ⓘ
Returns an iterator of nodes to this node and the siblings before it.
Includes the current node.
sourcepub fn following_siblings(&self) -> FollowingSiblings<T> ⓘ
pub fn following_siblings(&self) -> FollowingSiblings<T> ⓘ
Returns an iterator of nodes to this node and the siblings after it.
Includes the current node.
sourcepub fn children(&self) -> Children<T> ⓘ
pub fn children(&self) -> Children<T> ⓘ
Returns an iterator of nodes to this node’s children.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true
if this node has children nodes.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn descendants(&self) -> Descendants<T> ⓘ
pub fn descendants(&self) -> Descendants<T> ⓘ
Returns an iterator of nodes to this node and its descendants, in tree order.
Includes the current node.
sourcepub fn traverse(&self) -> Traverse<T> ⓘ
pub fn traverse(&self) -> Traverse<T> ⓘ
Returns an iterator of nodes to this node and its descendants, in tree order.
sourcepub fn detach(&self)
pub fn detach(&self)
Detaches a node from its parent and siblings. Children are not affected.
Panics
Panics if the node or one of its adjoining nodes is currently borrowed.
sourcepub fn append(&self, new_child: Node<T>)
pub fn append(&self, new_child: Node<T>)
Appends a new child to this node, after existing children.
Panics
Panics if the node, the new child, or one of their adjoining nodes is currently borrowed.
sourcepub fn prepend(&self, new_child: Node<T>)
pub fn prepend(&self, new_child: Node<T>)
Prepends a new child to this node, before existing children.
Panics
Panics if the node, the new child, or one of their adjoining nodes is currently borrowed.
sourcepub fn insert_after(&self, new_sibling: Node<T>)
pub fn insert_after(&self, new_sibling: Node<T>)
Inserts a new sibling after this node.
Panics
Panics if the node, the new sibling, or one of their adjoining nodes is currently borrowed.
sourcepub fn insert_before(&self, new_sibling: Node<T>)
pub fn insert_before(&self, new_sibling: Node<T>)
Inserts a new sibling before this node.
Panics
Panics if the node, the new sibling, or one of their adjoining nodes is currently borrowed.
sourcepub fn make_copy(&self) -> Node<T>where
T: Clone,
pub fn make_copy(&self) -> Node<T>where
T: Clone,
Returns a copy of a current node without children.
Panics
Panics if the node is currently mutably borrowed.
sourcepub fn make_deep_copy(&self) -> Node<T>where
T: Clone,
pub fn make_deep_copy(&self) -> Node<T>where
T: Clone,
Returns a copy of a current node with children.
Panics
Panics if any of the descendant nodes are currently mutably borrowed.
Trait Implementations§
source§impl<T> Clone for Node<T>
impl<T> Clone for Node<T>
Cloning a Node
only increments a reference count. It does not copy the data.