pub fn format_expr_restricted(
expr: &Expr,
source: &str,
depth: usize,
restriction: ExpressionRestriction,
) -> StringExpand description
Formats an embedded expression while preserving a header’s brace reservation.
Groups the complete header when an otherwise unparenthesized record would be ambiguous. Ordinary delimiters and nested branch bodies retain their normal formatting.
- Precondition:
sourceis the parsed source, or empty for a hand-built AST. - Complexity: O(n) document space plus layout and existing source-gap scans.
§Examples
use cel_parser::{AstContext, ExpressionRestriction, OpLookup, Parser, format_expr_restricted};
let source = "(Point { x: 1.0 }).x";
let ast = Parser::<AstContext>::new(OpLookup::new()).parse_str_ast(source).unwrap();
let text = format_expr_restricted(&ast, source, 0, ExpressionRestriction::NoStructLiteral);
assert_eq!(text, "(Point { x: 1.0 }.x)");