Skip to content

Commit 8882285

Browse files
committed
add docs
1 parent 9279c6a commit 8882285

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

datafusion/common/src/tree_node.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
453461
pub 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)]
498507
pub enum TreeNodeRecursion {
499508
/// Continue the visit to the next node.
@@ -515,6 +524,8 @@ pub enum TreeNodeRecursion {
515524
}
516525

517526
impl 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

Comments
 (0)