Skip to main content

Scope

Struct Scope 

Source
pub struct Scope {
    pub scope_type: ScopeType,
    pub sources: HashMap<String, Source>,
    pub columns: Vec<ColumnRef>,
    pub external_columns: Vec<ColumnRef>,
    pub derived_table_scopes: Vec<Scope>,
    pub subquery_scopes: Vec<Scope>,
    pub union_scopes: Vec<Scope>,
    pub cte_scopes: Vec<Scope>,
    pub selected_sources: HashMap<String, Source>,
    pub is_correlated: bool,
    /* private fields */
}
Expand description

Represents a single query scope and its relationships.

A scope is the context created by a query level (a SELECT, each branch of a UNION, each CTE definition, etc.). It tracks what tables are visible, what columns are referenced, and how nested scopes relate.

Fields§

§scope_type: ScopeType

What kind of scope this is.

§sources: HashMap<String, Source>

Mapping of source name/alias → Source. For tables this is alias.unwrap_or(name) → Source::Table(...). For derived tables / CTEs it is alias → Source::Scope(...).

§columns: Vec<ColumnRef>

All column references found directly in this scope (not in child subquery scopes).

§external_columns: Vec<ColumnRef>

Columns that reference an outer scope (correlation).

§derived_table_scopes: Vec<Scope>

Child scopes created by derived tables (subqueries in FROM).

§subquery_scopes: Vec<Scope>

Child scopes created by scalar subqueries (in SELECT / WHERE / HAVING).

§union_scopes: Vec<Scope>

Child scopes for each branch of a UNION / INTERSECT / EXCEPT.

§cte_scopes: Vec<Scope>

Child scopes for CTE definitions.

§selected_sources: HashMap<String, Source>

Sources that are actually referenced by columns in SELECT (subset of sources). Keyed the same way as sources.

§is_correlated: bool

Whether this scope contains correlated references to an outer scope.

Implementations§

Source§

impl Scope

Source

pub fn source_names(&self) -> Vec<&str>

Names (aliases / table names) of all sources visible in this scope.

Source

pub fn child_scopes(&self) -> Vec<&Scope>

Iterate over all child scopes (derived tables, subqueries, unions, CTEs) in a flat list.

Source

pub fn walk<F>(&self, visitor: &mut F)
where F: FnMut(&Scope),

Walk through all scopes in the tree (pre-order).

Trait Implementations§

Source§

impl Clone for Scope

Source§

fn clone(&self) -> Scope

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Scope

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Scope

§

impl RefUnwindSafe for Scope

§

impl Send for Scope

§

impl Sync for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin for Scope

§

impl UnwindSafe for Scope

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.