Struct comrak::arena_tree::Node

source ·
pub struct Node<'a, T: 'a> {
    pub data: T,
    /* private fields */
}
Expand description

A node inside a DOM-like tree.

Fields§

§data: T

The data held by the node.

Implementations§

source§

impl<'a, T> Node<'a, T>

source

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

Create a new node from its associated data.

Typically, this node needs to be moved into an arena allocator before it can be used in a tree.

source

pub fn parent(&self) -> Option<&'a Node<'a, T>>

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

source

pub fn first_child(&self) -> Option<&'a Node<'a, T>>

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

source

pub fn last_child(&self) -> Option<&'a Node<'a, T>>

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

source

pub fn previous_sibling(&self) -> Option<&'a Node<'a, T>>

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

source

pub fn next_sibling(&self) -> Option<&'a Node<'a, T>>

Return a reference to the next sibling of this node, unless it is a last child.

source

pub fn same_node(&self, other: &Node<'a, T>) -> bool

Returns whether two references point to the same node.

source

pub fn ancestors(&'a self) -> Ancestors<'a, 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(&'a self) -> PrecedingSiblings<'a, 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(&'a self) -> FollowingSiblings<'a, 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(&'a self) -> Children<'a, T>

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

source

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

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

source

pub fn descendants(&'a self) -> Descendants<'a, 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.

Similar Functions: Use traverse() or reverse_traverse if you need references to the NodeEdge structs associated with each Node

source

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

Return an iterator of references to NodeEdge enums for each Node and its descendants, in tree order.

NodeEdge enums represent the Start or End of each node.

Similar Functions: Use descendants() if you don’t need Start and End.

source

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

Return an iterator of references to NodeEdge enums for each Node and its descendants, in reverse order.

NodeEdge enums represent the Start or End of each node.

Similar Functions: Use descendants() if you don’t need Start and End.

source

pub fn detach(&self)

Detach a node from its parent and siblings. Children are not affected.

source

pub fn append(&'a self, new_child: &'a Node<'a, T>)

Append a new child to this node, after existing children.

source

pub fn prepend(&'a self, new_child: &'a Node<'a, T>)

Prepend a new child to this node, before existing children.

source

pub fn insert_after(&'a self, new_sibling: &'a Node<'a, T>)

Insert a new sibling after this node.

source

pub fn insert_before(&'a self, new_sibling: &'a Node<'a, T>)

Insert a new sibling before this node.

Trait Implementations§

source§

impl<'a, T> Debug for Node<'a, T>
where T: Debug + 'a,

A simple Debug implementation that prints the children as a tree, without looping through the various interior pointer cycles.

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T> !Freeze for Node<'a, T>

§

impl<'a, T> !RefUnwindSafe for Node<'a, T>

§

impl<'a, T> !Send for Node<'a, T>

§

impl<'a, T> !Sync for Node<'a, T>

§

impl<'a, T> Unpin for Node<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for Node<'a, 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, 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.