Struct NodeRef

Source
pub struct NodeRef<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 NodeRef only increments a reference count. It does not copy the data.

Implementations§

Source§

impl<T> NodeRef<T>

Source

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

Create a new node from its associated data.

Source

pub fn parent(&self) -> Option<NodeRef<T>>

Return a reference to the parent node, unless this node is the root of the tree.

§Panics

Panics if the node is currently mutability borrowed.

Source

pub fn first_child(&self) -> Option<NodeRef<T>>

Return a reference to the first child of this node, unless it has no child.

§Panics

Panics if the node is currently mutability borrowed.

Source

pub fn last_child(&self) -> Option<NodeRef<T>>

Return a reference to the last child of this node, unless it has no child.

§Panics

Panics if the node is currently mutability borrowed.

Source

pub fn previous_sibling(&self) -> Option<NodeRef<T>>

Return a reference to the previous sibling of this node, unless it is a first child.

§Panics

Panics if the node is currently mutability borrowed.

Source

pub fn next_sibling(&self) -> Option<NodeRef<T>>

Return a reference to the previous sibling of this node, unless it is a first child.

§Panics

Panics if the node is currently mutability borrowed.

Source

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

Return a shared reference to this node’s data

§Panics

Panics if the node is currently mutability borrowed.

Source

pub fn borrow_mut(&self) -> RefMut<'_, T>

Return a unique/mutable reference to this node’s data

§Panics

Panics if the node is currently borrowed.

Source

pub fn same_node(&self, other: &NodeRef<T>) -> bool

Returns whether two references point to the same node.

Source

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

Return an iterator of references to this node and its ancestors.

Call .next().unwrap() once on the iterator to skip the node itself.

Source

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

Return an iterator of references to this node and the siblings before it.

Call .next().unwrap() once on the iterator to skip the node itself.

Source

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

Return an iterator of references to this node and the siblings after it.

Call .next().unwrap() once on the iterator to skip the node itself.

Source

pub fn children(&self) -> Children<T>

Return an iterator of references to this node’s children.

§Panics

Panics if the node is currently mutability borrowed.

Source

pub fn reverse_children(&self) -> ReverseChildren<T>

Return an iterator of references to this node’s children, in reverse order.

§Panics

Panics if the node is currently mutability borrowed.

Source

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

Return an iterator of references to this node and its descendants, in tree order.

Parent nodes appear before the descendants. Call .next().unwrap() once on the iterator to skip the node itself.

Source

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

Return an iterator of references to this node and its descendants, in tree order.

Source

pub fn reverse_traverse(&self) -> ReverseTraverse<T>

Return an iterator of references to this node and its descendants, in tree order.

Source

pub fn detach(&self)

Detach 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: NodeRef<T>)

Append 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: NodeRef<T>)

Prepend 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: NodeRef<T>)

Insert 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: NodeRef<T>)

Insert a new sibling before this node.

§Panics

Panics if the node, the new sibling, or one of their adjoining nodes is currently borrowed.

Trait Implementations§

Source§

impl<T> Clone for NodeRef<T>

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

Source§

fn clone(&self) -> NodeRef<T>

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 NodeRef<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for NodeRef<T>

§

impl<T> !RefUnwindSafe for NodeRef<T>

§

impl<T> !Send for NodeRef<T>

§

impl<T> !Sync for NodeRef<T>

§

impl<T> Unpin for NodeRef<T>

§

impl<T> !UnwindSafe for NodeRef<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, 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.