Skip to main content

RenderCtx

Struct RenderCtx 

Source
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>

Source

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.

Source

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_SYMBOL placeholder 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.
Source

pub fn resolver(&self) -> &dyn Resolver

The resolver used to turn Symbols back into identifier text.

Source

pub fn source(&self) -> &str

The original source text that literals are sliced from.

Source

pub fn config(&self) -> &RenderConfig

The active render configuration.

Source

pub fn mode(&self) -> RenderMode

The active render mode.

Source

pub fn target(&self) -> &FeatureSet

The active target dialect feature set.

Source

pub fn spelling(&self) -> RenderSpelling

The active spelling policy.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for RenderCtx<'a>

§

impl<'a> !Send for RenderCtx<'a>

§

impl<'a> !Sync for RenderCtx<'a>

§

impl<'a> !UnwindSafe for RenderCtx<'a>

§

impl<'a> Freeze for RenderCtx<'a>

§

impl<'a> Unpin for RenderCtx<'a>

§

impl<'a> UnsafeUnpin for RenderCtx<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.