Skip to main content

map_children_crossing

Function map_children_crossing 

Source
pub fn map_children_crossing<C>(
    expr: SqlExpression,
    ctx: &mut C,
    f: impl FnMut(&mut C, SqlExpression) -> SqlExpression,
    f_stmt: impl FnMut(&mut C, Box<SelectStatement>) -> Box<SelectStatement>,
) -> SqlExpression
Expand description

Rebuild expr, replacing each direct child expression with f(ctx, child) and each directly nested subquery statement with f_stmt(ctx, stmt).

This is the primitive map_children is built on; it is the only exhaustive match over SqlExpression in the rewrite path. Callers that must reach into nested statements (CTE hoisting, INTO removal, scope-independent operator rewrites) use this instead of hand-listing the subquery variants, so a newly added subquery-bearing variant breaks the build here rather than being silently skipped at each call site.

ctx carries whatever mutable state the two closures share — typically the transformer itself. See the module docs for why it is a parameter rather than a capture.

f_stmt takes and returns the Box, not the statement, so that the opaque case (map_children, whose handler is |_, stmt| stmt) is a passthrough rather than an unbox/realloc of a large struct at every subquery.