Struct rctree::Node

source ·
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>

source

pub fn new(data: T) -> Node<T>

Creates a new node from its associated data.

source

pub fn downgrade(&self) -> WeakNode<T>

Returns a weak reference to a node.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn borrow(&self) -> Ref<'_, T>

Returns a shared reference to this node’s data.

Panics

Panics if the node is currently mutably borrowed.

source

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.

source

pub fn ancestors(&self) -> Ancestors<T>

Returns an iterator of nodes to this node and its ancestors.

Includes the current node.

source

pub fn preceding_siblings(&self) -> PrecedingSiblings<T>

Returns an iterator of nodes to this node and the siblings before it.

Includes the current node.

source

pub fn following_siblings(&self) -> FollowingSiblings<T>

Returns an iterator of nodes to this node and the siblings after it.

Includes the current node.

source

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.

source

pub fn has_children(&self) -> bool

Returns true if this node has children nodes.

Panics

Panics if the node is currently mutably borrowed.

source

pub fn descendants(&self) -> Descendants<T>

Returns an iterator of nodes to this node and its descendants, in tree order.

Includes the current node.

source

pub fn traverse(&self) -> Traverse<T>

Returns an iterator of nodes to this node and its descendants, in tree order.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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>

Cloning a Node only increments a reference count. It does not copy the data.

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Node<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Display> Display for Node<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> PartialEq for Node<T>

source§

fn eq(&self, other: &Node<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Node<T>

§

impl<T> !Send for Node<T>

§

impl<T> !Sync for Node<T>

§

impl<T> Unpin for Node<T>

§

impl<T> !UnwindSafe for Node<T>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.