Search an `Expr`, and all of its nested `Expr`'s, for any that pass the provided test. The returned `Expr`'s are deduplicated and returned in order of appearance (depth first).
(expr: &Expr, test_fn: &F)
| 693 | /// provided test. The returned `Expr`'s are deduplicated and returned in order |
| 694 | /// of appearance (depth first). |
| 695 | fn find_exprs_in_expr<F>(expr: &Expr, test_fn: &F) -> Vec<Expr> |
| 696 | where |
| 697 | F: Fn(&Expr) -> bool, |
| 698 | { |
| 699 | let mut exprs = vec![]; |
| 700 | expr.apply(|expr| { |
| 701 | if test_fn(expr) { |
| 702 | if !(exprs.contains(expr)) { |
| 703 | exprs.push(expr.clone()) |
| 704 | } |
| 705 | // Stop recursing down this expr once we find a match |
| 706 | return Ok(TreeNodeRecursion::Jump); |
| 707 | } |
| 708 | |
| 709 | Ok(TreeNodeRecursion::Continue) |
| 710 | }) |
| 711 | // pre_visit always returns OK, so this will always too |
| 712 | .expect("no way to return error during recursion"); |
| 713 | exprs |
| 714 | } |
| 715 | |
| 716 | /// Recursively inspect an [`Expr`] and all its children. |
| 717 | pub fn inspect_expr_pre<F, E>(expr: &Expr, mut f: F) -> Result<(), E> |
no test coverage detected
searching dependent graphs…