@@ -428,7 +428,7 @@ pub trait TreeNode: Sized {
428428}
429429
430430/// Implements the [visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) for
431- /// recursively walking [`TreeNode`]s.
431+ /// recursively visiting [`TreeNode`]s.
432432///
433433/// [`TreeNodeVisitor`] allows keeping the algorithms separate from the code to traverse
434434/// the structure of the [`TreeNode`] tree and makes it easier to add new types of tree
@@ -450,6 +450,14 @@ pub trait TreeNodeVisitor: Sized {
450450 fn post_visit ( & mut self , _node : & Self :: Node ) -> Result < TreeNodeRecursion > ;
451451}
452452
453+ /// Implements the [visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) for
454+ /// recursively transforming [`TreeNode`]s.
455+ ///
456+ /// When passed to [`TreeNode::transform()`], [`TreeNodeVisitor::pre_transform()`] and
457+ /// [`TreeNodeVisitor::post_transform()`] are invoked recursively on an node tree.
458+ /// See [`TreeNodeRecursion`] for more details on how the traversal can be controlled.
459+ ///
460+ /// If an [`Err`] result is returned, recursion is stopped immediately.
453461pub trait TreeNodeTransformer : Sized {
454462 /// The node type which is visitable.
455463 type Node : TreeNode ;
@@ -492,8 +500,9 @@ pub enum RewriteRecursion {
492500 Skip ,
493501}
494502
495- /// Controls how the [`TreeNode`] recursion should proceed for [`TreeNode::visit_down()`] and
496- /// [`TreeNode::visit()`].
503+ /// Controls how a [`TreeNode`] recursion should proceed for [`TreeNode::visit_down()`],
504+ /// [`TreeNode::visit()`], [`TreeNode::transform_down()`], [`TreeNode::transform_up()`]
505+ /// and [`TreeNode::transform()`].
497506#[ derive( Debug ) ]
498507pub enum TreeNodeRecursion {
499508 /// Continue the visit to the next node.
@@ -515,6 +524,8 @@ pub enum TreeNodeRecursion {
515524}
516525
517526impl TreeNodeRecursion {
527+ /// Helper function to define behavior of a [`TreeNode`] recursion to continue with a
528+ /// closure if the recursion so far resulted [`TreeNodeRecursion::Continue]`.
518529 pub fn and_then_on_continue < F > ( self , f : F ) -> Result < TreeNodeRecursion >
519530 where
520531 F : FnOnce ( ) -> Result < TreeNodeRecursion > ,
@@ -525,7 +536,7 @@ impl TreeNodeRecursion {
525536 }
526537 }
527538
528- pub fn continue_on_prune ( self ) -> Result < TreeNodeRecursion > {
539+ fn continue_on_prune ( self ) -> Result < TreeNodeRecursion > {
529540 Ok ( match self {
530541 TreeNodeRecursion :: Prune => TreeNodeRecursion :: Continue ,
531542 o => o,
@@ -539,7 +550,7 @@ impl TreeNodeRecursion {
539550 } )
540551 }
541552
542- pub fn continue_on_stop ( self ) -> Result < TreeNodeRecursion > {
553+ fn continue_on_stop ( self ) -> Result < TreeNodeRecursion > {
543554 Ok ( match self {
544555 TreeNodeRecursion :: Stop => TreeNodeRecursion :: Continue ,
545556 o => o,
0 commit comments