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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
Sourcepub fn read(&self) -> MappedRwLockReadGuard<'_, T>
pub fn read(&self) -> MappedRwLockReadGuard<'_, T>
Returns an RAII guard that allows read access to the node’s data.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
Sourcepub fn write(&self) -> MappedRwLockWriteGuard<'_, T>
pub fn write(&self) -> MappedRwLockWriteGuard<'_, T>
Returns an RAII guard that allows write access to the node’s data.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Returns true if this node has children nodes.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
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.
Calling this method will block the current thread until the lock is available.
Refer to RwLock for more information.
Trait Implementations§
Source§impl<T> Clone for Node<T>
Cloning a Node only increments a reference count. It does not copy the data.
impl<T> Clone for Node<T>
Cloning a Node only increments a reference count. It does not copy the data.