pub fn canonicalize_directives<'a, I>(
directives: I,
config: &FormatConfig,
) -> Result<String, CanonicalizeError>Expand description
Render typed Beancount Directives in the canonical form
emitted by format_source.
Two-pass pipeline:
- Synthesize a source string via the typed-directive emitter
in
rustledger_core::format::format_directives. That emitter isDirective → text; its output is bean-format- style, parser-clean, and used here purely as an intermediate. - Re-parse the synthesized text. If the legacy emitter
produced something the new parser cannot fully accept,
return
CanonicalizeError::ReparseFailedrather than silently emitting the recoverable subset — that silent-loss failure mode is what the oldercrates/rustledger/tests/ format_compat.rs(deleted in phase 4.1, distinct from the phase 4.2 file-pair suite atcrates/rustledger-parser/ tests/format_compat/) used to guard against. The new file- pair suite exercisesformat_source, not this two-pass shim; a future change tocanonicalize_directives’s error semantics needs its own dedicated regression test. - Run the re-parsed text through
format_sourcefor the canonical pass.
Single source of truth for the synthesize → canonicalize
shim. Every consumer that builds a typed Directive in memory
and wants canonical text — rledger add, rledger extract,
the FFI format.entry / format.entries endpoints — should
call this function instead of reinventing the pipeline.