Applies `f` to the node then each of its children, recursively (a top-down, pre-order traversal). The return [`TreeNodeRecursion`] controls the recursion and can cause an early return. # See Also [`Self::transform_down`] for the equivalent transformation API. [`Self::visit`] for both top-down and bottom up traversal.
(
&'n self,
mut f: F,
)
| 194 | /// * [`Self::transform_down`] for the equivalent transformation API. |
| 195 | /// * [`Self::visit`] for both top-down and bottom up traversal. |
| 196 | fn apply<'n, F: FnMut(&'n Self) -> Result<TreeNodeRecursion>>( |
| 197 | &'n self, |
| 198 | mut f: F, |
| 199 | ) -> Result<TreeNodeRecursion> { |
| 200 | #[cfg_attr(feature = "recursive_protection", recursive::recursive)] |
| 201 | fn apply_impl<'n, N: TreeNode, F: FnMut(&'n N) -> Result<TreeNodeRecursion>>( |
| 202 | node: &'n N, |
| 203 | f: &mut F, |
| 204 | ) -> Result<TreeNodeRecursion> { |
| 205 | f(node)?.visit_children(|| node.apply_children(|c| apply_impl(c, f))) |
| 206 | } |
| 207 | |
| 208 | apply_impl(self, &mut f) |
| 209 | } |
| 210 | |
| 211 | /// Recursively rewrite the node's children and then the node using `f` |
| 212 | /// (a bottom-up post-order traversal). |
no outgoing calls