Skip to main content

TreeContext

Struct TreeContext 

Source
pub struct TreeContext { /* private fields */ }
Expand description

External parent-tracking context for an expression tree.

Since Rust’s ownership model does not allow intrusive parent pointers in the AST, TreeContext provides an on-demand side-table that maps each node (identified by a NodeId) to its ParentInfo (parent node, field name, and list index).

Build a context from any expression root with TreeContext::build, then query parent relationships with get, ancestry chains with ancestors_of, or tree depth with depth_of.

This is useful when analysis requires upward navigation (e.g., determining whether a column reference appears inside a WHERE clause or a JOIN condition).

Implementations§

Source§

impl TreeContext

Source

pub fn new() -> Self

Create a new empty tree context

Source

pub fn build(root: &Expression) -> Self

Build context from an expression tree

Source

pub fn get(&self, id: NodeId) -> Option<&ParentInfo>

Get parent info for a node

Source

pub fn depth_of(&self, id: NodeId) -> usize

Get the depth of a node (0 for root)

Source

pub fn ancestors_of(&self, id: NodeId) -> Vec<NodeId>

Get ancestors of a node (parent, grandparent, etc.)

Trait Implementations§

Source§

impl Debug for TreeContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TreeContext

Source§

fn default() -> TreeContext

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.