Skip to main content

format_node_with_alignment

Function format_node_with_alignment 

Source
pub fn format_node_with_alignment(
    node: &SyntaxNode,
    alignment: PostingAlignment,
) -> String
Expand description

Like format_node but skips the per-call compute_alignment walk by accepting a precomputed PostingAlignment.

The cache pattern: parse → take ParseResult::alignment (the pre-computed file-wide alignment, populated by parse_via_cst) → call this function. Subsequent formatting calls on the same ParseResult pay only the per-call emit cost, not the O(N_postings) pre-pass.

alignment MUST match what compute_alignment(&SourceFile::cast(node).unwrap()) would return for the given node — passing a mismatched alignment is allowed but produces output with non-canonical column widths. Use PostingAlignment::default() for files known to have no postings (no transactions, or transactions with no AMOUNT).

§Panics

Panics if node’s kind is not SOURCE_FILE.