pub struct RenderCtx<'a> { /* private fields */ }Expand description
Resolver, source, and config threaded through every Render call.
The Resolver trait (not the concrete interner) lives in this crate, so the
renderer stays independent of parser internals. config is borrowed, not
owned: a multi-statement render builds one RenderCtx per statement (or per
render — see the parser crate’s Parsed::to_sql), and RenderConfig is large
enough — it embeds the whole target FeatureSet, keyword/precedence tables and
all — that owning a fresh copy each time was a real per-statement memcpy of data
that never changes across a render.
Implementations§
Source§impl<'a> RenderCtx<'a>
impl<'a> RenderCtx<'a>
Sourcepub fn new(
resolver: &'a dyn Resolver,
source: &'a str,
config: &'a RenderConfig,
) -> Self
pub fn new( resolver: &'a dyn Resolver, source: &'a str, config: &'a RenderConfig, ) -> Self
Build a canonical context from a resolver, the original source text, and config.
This is the canonical render path: the resolver and source must
come from the same parse as the node, because resolution is strict (a
foreign symbol panics) and literals slice their exact source spelling. Prefer
it — and the Displayed wrapper or the parser crate’s directly-Display
Parsed root over it — whenever the matched context is in hand. For a
detached node whose context may not match, reach for the tolerant
debug sibling instead.
config is borrowed, so building a ctx per statement (a multi-statement
render’s loop) costs copying a pointer, never a RenderConfig copy.
Sourcepub fn debug(resolver: &'a dyn Resolver, config: &'a RenderConfig) -> Self
pub fn debug(resolver: &'a dyn Resolver, config: &'a RenderConfig) -> Self
Build the opt-in debug context: an explicitly-supplied resolver with tolerant resolution and no source slicing (the debug-SQL mitigation).
Use this — or the RenderExt::debug_sql convenience over it — to render a
detached or synthesized node for debugging, where the canonical
new path’s guarantees may not hold:
- The resolver is an explicit argument, never a hidden global or default,
so debug rendering can never silently pick the wrong resolver — the choice
is always visible at the call site. (A resolver from a different parse can
still mis-resolve a numerically-colliding symbol; only the canonical path,
which travels with its own resolver, rules that out. See
debug_sql.) - A symbol the resolver does not know renders the
UNRESOLVED_SYMBOLplaceholder instead of panicking, so a partially-detached tree renders to completion. - Source is deliberately not an argument: debug rendering never slices it, so a literal always uses its kind-based spelling and can never emit unrelated bytes from a mismatched source. For exact literal text, use the canonical path, which owns the matched source.
Sourcepub fn resolver(&self) -> &dyn Resolver
pub fn resolver(&self) -> &dyn Resolver
The resolver used to turn Symbols back into identifier text.
Sourcepub fn config(&self) -> &RenderConfig
pub fn config(&self) -> &RenderConfig
The active render configuration.
Sourcepub fn mode(&self) -> RenderMode
pub fn mode(&self) -> RenderMode
The active render mode.
Sourcepub fn target(&self) -> &FeatureSet
pub fn target(&self) -> &FeatureSet
The active target dialect feature set.
Sourcepub fn spelling(&self) -> RenderSpelling
pub fn spelling(&self) -> RenderSpelling
The active spelling policy.