File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -380,8 +380,22 @@ impl Ast {
380380/// It is bound by the lifetime `'a`, which corresponds to the `Arena` nodes are allocated in.
381381/// `AstNode`s are almost handled as a reference itself bound by `'a`. Child `Ast`s are wrapped in
382382/// `RefCell` for interior mutability.
383+ ///
384+ /// You can construct a new `AstNode` from a `NodeValue` using the `From` trait:
385+ ///
386+ /// ```no_run
387+ /// # use comrak::nodes::{AstNode, NodeValue};
388+ /// let root = AstNode::from(NodeValue::Document);
389+ /// ```
383390pub type AstNode < ' a > = Node < ' a , RefCell < Ast > > ;
384391
392+ impl < ' a > From < NodeValue > for AstNode < ' a > {
393+ /// Create a new AST node with the given value.
394+ fn from ( value : NodeValue ) -> Self {
395+ Node :: new ( RefCell :: new ( Ast :: new ( value) ) )
396+ }
397+ }
398+
385399#[ doc( hidden) ]
386400pub fn last_child_is_open < ' a > ( node : & ' a AstNode < ' a > ) -> bool {
387401 node. last_child ( ) . map_or ( false , |n| n. data . borrow ( ) . open )
You can’t perform that action at this time.
0 commit comments