pub struct ScopeTracker { /* private fields */ }Expand description
Tracks variable declarations across nested scopes
Used during code generation to determine whether a variable assignment
should generate let mut x = ... (new declaration) or x = ... (reassignment).
Implementations§
Source§impl ScopeTracker
impl ScopeTracker
Sourcepub fn enter_scope(&mut self)
pub fn enter_scope(&mut self)
Enter a new nested scope
Variables declared in this scope will be removed when exit_scope is called.
Sourcepub fn exit_scope(&mut self) -> bool
pub fn exit_scope(&mut self) -> bool
Exit the current scope
Returns true if a scope was exited, false if already at the outermost scope.
Sourcepub fn is_declared(&self, var_name: &str) -> bool
pub fn is_declared(&self, var_name: &str) -> bool
Check if a variable is declared in any enclosing scope
Sourcepub fn is_declared_in_current_scope(&self, var_name: &str) -> bool
pub fn is_declared_in_current_scope(&self, var_name: &str) -> bool
Check if a variable is declared in the current (innermost) scope only
Sourcepub fn declare_var(&mut self, var_name: &str) -> bool
pub fn declare_var(&mut self, var_name: &str) -> bool
Declare a variable in the current scope
Returns true if the variable was newly declared, false if it was already declared.
Sourcepub fn scope_depth(&self) -> usize
pub fn scope_depth(&self) -> usize
Get the number of nested scopes (1 = outermost only)
Sourcepub fn all_declared_vars(&self) -> HashSet<String>
pub fn all_declared_vars(&self) -> HashSet<String>
Get all declared variables across all scopes
Sourcepub fn current_scope_vars(&self) -> Option<&HashSet<String>>
pub fn current_scope_vars(&self) -> Option<&HashSet<String>>
Get variables declared in the current scope only
Sourcepub fn declare_vars<I>(&mut self, var_names: I)
pub fn declare_vars<I>(&mut self, var_names: I)
Declare multiple variables at once in the current scope
Useful for tuple unpacking: let (a, b, c) = ...
Trait Implementations§
Source§impl Clone for ScopeTracker
impl Clone for ScopeTracker
Source§fn clone(&self) -> ScopeTracker
fn clone(&self) -> ScopeTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ScopeTracker
impl Debug for ScopeTracker
Auto Trait Implementations§
impl Freeze for ScopeTracker
impl RefUnwindSafe for ScopeTracker
impl Send for ScopeTracker
impl Sync for ScopeTracker
impl Unpin for ScopeTracker
impl UnsafeUnpin for ScopeTracker
impl UnwindSafe for ScopeTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more