pub trait TreeNodeRewritable: Clone {
// Required method
fn map_children<F>(self, transform: F) -> Result<Self>
where F: FnMut(Self) -> Result<Self>;
// Provided methods
fn transform_using<R: TreeNodeRewriter<Self>>(
self,
rewriter: &mut R
) -> Result<Self> { ... }
fn transform<F>(self, op: &F) -> Result<Self>
where F: Fn(Self) -> Result<Option<Self>> { ... }
fn transform_down<F>(self, op: &F) -> Result<Self>
where F: Fn(Self) -> Result<Option<Self>> { ... }
fn transform_up<F>(self, op: &F) -> Result<Self>
where F: Fn(Self) -> Result<Option<Self>> { ... }
}
Expand description
a Trait for marking tree node types that are rewritable
Required Methods§
sourcefn map_children<F>(self, transform: F) -> Result<Self>where
F: FnMut(Self) -> Result<Self>,
fn map_children<F>(self, transform: F) -> Result<Self>where F: FnMut(Self) -> Result<Self>,
Apply transform F
to the node’s children, the transform F
might have a direction(Preorder or Postorder)
Provided Methods§
sourcefn transform_using<R: TreeNodeRewriter<Self>>(
self,
rewriter: &mut R
) -> Result<Self>
fn transform_using<R: TreeNodeRewriter<Self>>( self, rewriter: &mut R ) -> Result<Self>
Transform the tree node using the given TreeNodeRewriter It performs a depth first walk of an node and its children.
For an node tree such as
ParentNode
left: ChildNode1
right: ChildNode2
The nodes are visited using the following order
pre_visit(ParentNode)
pre_visit(ChildNode1)
mutate(ChildNode1)
pre_visit(ChildNode2)
mutate(ChildNode2)
mutate(ParentNode)
If an Err result is returned, recursion is stopped immediately
If false
is returned on a call to pre_visit, no
children of that node are visited, nor is mutate
called on that node
sourcefn transform<F>(self, op: &F) -> Result<Self>where
F: Fn(Self) -> Result<Option<Self>>,
fn transform<F>(self, op: &F) -> Result<Self>where F: Fn(Self) -> Result<Option<Self>>,
Convenience utils for writing optimizers rule: recursively apply the given op
to the node tree.
When op
does not apply to a given node, it is left unchanged.
The default tree traversal direction is transform_up(Postorder Traversal).
sourcefn transform_down<F>(self, op: &F) -> Result<Self>where
F: Fn(Self) -> Result<Option<Self>>,
fn transform_down<F>(self, op: &F) -> Result<Self>where F: Fn(Self) -> Result<Option<Self>>,
Convenience utils for writing optimizers rule: recursively apply the given ‘op’ to the node and all of its
children(Preorder Traversal).
When the op
does not apply to a given node, it is left unchanged.
sourcefn transform_up<F>(self, op: &F) -> Result<Self>where
F: Fn(Self) -> Result<Option<Self>>,
fn transform_up<F>(self, op: &F) -> Result<Self>where F: Fn(Self) -> Result<Option<Self>>,
Convenience utils for writing optimizers rule: recursively apply the given ‘op’ first to all of its
children and then itself(Postorder Traversal).
When the op
does not apply to a given node, it is left unchanged.