Node

Struct 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.

Calling this method will block the current thread until the lock is available. Refer to RwLock for more information.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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.

Calling this method will block the current thread until the lock is available. Refer to RwLock for more information.

Source

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.

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.

Calling this method will block the current thread until the lock is available. Refer to RwLock for more information.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source§

fn clone(&self) -> Self

Returns a duplicate 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Auto Trait Implementations§

§

impl<T> Freeze for Node<T>

§

impl<T> !RefUnwindSafe for Node<T>

§

impl<T> Send for Node<T>
where T: Send + Sync,

§

impl<T> Sync for Node<T>
where T: Send + Sync,

§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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§

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>,

Source§

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>,

Source§

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.