Struct Node
struct Node<'a, T: 'a> { ... }
A node inside a DOM-like tree.
Fields
data: TThe data held by the node.
Implementations
impl<'a> crate::arena_tree::Node<'a, std::cell::RefCell<Ast>>
fn validate(self: &'a Self) -> Result<(), ValidationError<'a>>The comrak representation of a markdown node in Rust isn't strict enough to rule out invalid trees according to the CommonMark specification. One simple example is that block containers, such as lists, should only contain blocks, but it's possible to put naked inline text in a list item. Such invalid trees can lead comrak to generate incorrect output if rendered.
This method performs additional structural checks to ensure that a markdown AST is valid according to the CommonMark specification.
Note that those invalid trees can only be generated programmatically. Parsing markdown with comrak, on the other hand, should always produce a valid tree.
impl<'a, T> Node<'a, T>
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.
fn parent(self: &Self) -> Option<&'a Node<'a, T>>Return a reference to the parent node, unless this node is the root of the tree.
fn first_child(self: &Self) -> Option<&'a Node<'a, T>>Return a reference to the first child of this node, unless it has no child.
fn last_child(self: &Self) -> Option<&'a Node<'a, T>>Return a reference to the last child of this node, unless it has no child.
fn previous_sibling(self: &Self) -> Option<&'a Node<'a, T>>Return a reference to the previous sibling of this node, unless it is a first child.
fn next_sibling(self: &Self) -> Option<&'a Node<'a, T>>Return a reference to the next sibling of this node, unless it is a last child.
fn same_node(self: &Self, other: &Node<'a, T>) -> boolReturns whether two references point to the same node.
fn ancestors(self: &'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.fn preceding_siblings(self: &'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.fn following_siblings(self: &'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.fn children(self: &'a Self) -> Children<'a, T>Return an iterator of references to this node’s children.
fn reverse_children(self: &'a Self) -> ReverseChildren<'a, T>Return an iterator of references to this node’s children, in reverse order.
fn descendants(self: &'a Self) -> Descendants<'a, T>Return an iterator of references to this
Nodeand 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()orreverse_traverseif you need references to theNodeEdgestructs associated with eachNodefn traverse(self: &'a Self) -> Traverse<'a, T>Return an iterator of references to
NodeEdgeenums for eachNodeand its descendants, in tree order.NodeEdgeenums represent theStartorEndof each node.Similar Functions: Use
descendants()if you don't needStartandEnd.fn reverse_traverse(self: &'a Self) -> ReverseTraverse<'a, T>Return an iterator of references to
NodeEdgeenums for eachNodeand its descendants, in reverse order.NodeEdgeenums represent theStartorEndof each node.Similar Functions: Use
descendants()if you don't needStartandEnd.fn detach(self: &Self)Detach a node from its parent and siblings. Children are not affected.
fn append(self: &'a Self, new_child: &'a Node<'a, T>)Append a new child to this node, after existing children.
fn prepend(self: &'a Self, new_child: &'a Node<'a, T>)Prepend a new child to this node, before existing children.
fn insert_after(self: &'a Self, new_sibling: &'a Node<'a, T>)Insert a new sibling after this node.
fn insert_before(self: &'a Self, new_sibling: &'a Node<'a, T>)Insert a new sibling before this node.
impl<'a, T> Debug for Node<'a, T>
fn fmt(self: &Self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error>
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>
impl<'a, T> UnwindSafe for Node<'a, T>
impl<T> Any for Node<'a, T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Node<'a, T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Node<'a, T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Node<'a, T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Node<'a, T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Node<'a, T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Node<'a, T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>