Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,22 @@ impl Ast {
/// It is bound by the lifetime `'a`, which corresponds to the `Arena` nodes are allocated in.
/// `AstNode`s are almost handled as a reference itself bound by `'a`. Child `Ast`s are wrapped in
/// `RefCell` for interior mutability.
///
/// You can construct a new `AstNode` from a `NodeValue` using the `From` trait:
///
/// ```no_run
/// # use comrak::nodes::{AstNode, NodeValue};
/// let root = AstNode::from(NodeValue::Document);
/// ```
pub type AstNode<'a> = Node<'a, RefCell<Ast>>;

impl<'a> From<NodeValue> for AstNode<'a> {
/// Create a new AST node with the given value.
fn from(value: NodeValue) -> Self {
Node::new(RefCell::new(Ast::new(value)))
}
}

#[doc(hidden)]
pub fn last_child_is_open<'a>(node: &'a AstNode<'a>) -> bool {
node.last_child().map_or(false, |n| n.data.borrow().open)
Expand Down