pub enum LexicalScope<K, V> {
Empty,
Root(Box<HashMap<K, V>>),
Nested(Rc<LexicalScope<K, V>>, Box<HashMap<K, V>>),
}Expand description
A lexically scoped environment is essentially a hierarchical mapping of keys to values, where keys may be defined at multiple levels, but only a single definition at any point in the program is active - the definition closest to that point.
A LexicalScope starts out at the root, empty. Any number of keys may be inserted at the current scope, or a new nested scope may be entered. When entering a new nested scope, keys inserted there take precedence over the same keys in previous (higher) scopes, but do not overwrite those definitions. When exiting a scope, all definitions in that scope are discarded, and definitions from the parent scope take effect again.
When searching for keys, the search begins in the current scope, and searches upwards in the scope tree until either the root is reached and the search terminates, or the key is found in some intervening scope.
Variants§
Empty
An empty scope, this is the default state in which all LexicalScope start
Root(Box<HashMap<K, V>>)
Represents a non-empty, top-level (root) scope
Nested(Rc<LexicalScope<K, V>>, Box<HashMap<K, V>>)
Represents a (possibly empty) nested scope, as a tuple of the parent scope and the environment of the current scope.
Implementations§
Source§impl<K, V> LexicalScope<K, V>
impl<K, V> LexicalScope<K, V>
Source§impl<K, V> LexicalScope<K, V>
impl<K, V> LexicalScope<K, V>
Source§impl<K, V> LexicalScope<K, V>
impl<K, V> LexicalScope<K, V>
Sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
pub fn insert(&mut self, k: K, v: V) -> Option<V>
Inserts a new binding in the current scope, returning a conflicting definition if one is present (i.e. the same name was already declared in the same (current) scope).
NOTE: This does not return Some if a previous definition exists in an outer scope,
the new definition will shadow that one, but is not considered in conflict with it.
pub fn get<Q>(&self, key: &Q) -> Option<&V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
Sourcepub fn get_key<Q>(&self, key: &Q) -> Option<&K>
pub fn get_key<Q>(&self, key: &Q) -> Option<&K>
Gets the value of the key stored in this structure by key
This is used in some cases where a field of the key contains useful metadata (such as source spans), but is not part of the eq/hash impl. This function allows you to obtain the actual key stored in the map.
Trait Implementations§
Source§impl<K, V> Clone for LexicalScope<K, V>
impl<K, V> Clone for LexicalScope<K, V>
Source§impl<K, V> Default for LexicalScope<K, V>
impl<K, V> Default for LexicalScope<K, V>
Source§impl<K, V, Q> Index<&Q> for LexicalScope<K, V>
impl<K, V, Q> Index<&Q> for LexicalScope<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for LexicalScope<K, V>
impl<K, V> RefUnwindSafe for LexicalScope<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> !Send for LexicalScope<K, V>
impl<K, V> !Sync for LexicalScope<K, V>
impl<K, V> Unpin for LexicalScope<K, V>
impl<K, V> UnwindSafe for LexicalScope<K, V>
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> 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