pub struct PersistentScopedMap<K, V> { /* private fields */ }Expand description
Scoped hash table similar to hermes::ScopedHashTable, but scopes can be
retained and reactivated after they have been popped from the table. See
the module documentation for the full example and for the deviations
from the C++ implementation.
Implementations§
Source§impl<K: Eq + Hash + Copy, V: Clone> PersistentScopedMap<K, V>
impl<K: Eq + Hash + Copy, V: Clone> PersistentScopedMap<K, V>
pub fn new() -> Self
Sourcepub fn current_scope(&self) -> ScopePtr<K, V>
pub fn current_scope(&self) -> ScopePtr<K, V>
Return a pointer to the current scope. The pointer may be null.
Sourcepub fn try_emplace_into_scope(
&self,
scope: &ScopePtr<K, V>,
key: K,
value: V,
) -> bool
pub fn try_emplace_into_scope( &self, scope: &ScopePtr<K, V>, key: K, value: V, ) -> bool
Attempt to insert an element into the specified scope. Returns
whether the insertion took place (false if key already has a
binding in scope). A key may not be inserted such that it would be
shadowed by another scope currently in effect. Attempting to do so
results in undefined behavior.
Sourcepub fn try_emplace(&self, key: K, value: V) -> bool
pub fn try_emplace(&self, key: K, value: V) -> bool
Attempt to insert an element into the current scope. Returns whether the insertion took place.
Sourcepub fn put_in_scope(&self, scope: &ScopePtr<K, V>, key: K, value: V)
pub fn put_in_scope(&self, scope: &ScopePtr<K, V>, key: K, value: V)
Insert or update a value in the specified scope. A key may not be inserted such that it would be shadowed by another scope currently in effect. Attempting to do so results in undefined behavior.
Sourcepub fn lookup(&self, key: &K) -> Option<V>
pub fn lookup(&self, key: &K) -> Option<V>
Gets the innermost value for a key, or None if none.
Sourcepub fn find(&self, key: &K) -> Option<V>
pub fn find(&self, key: &K) -> Option<V>
Return the innermost value for a key, or None if none.
Sourcepub fn find_with_depth(&self, key: &K) -> Option<(V, u32)>
pub fn find_with_depth(&self, key: &K) -> Option<(V, u32)>
\return the innermost value for a key along with its depth, or None
if none.
Sourcepub fn find_in_current_scope(&self, key: &K) -> Option<V>
pub fn find_in_current_scope(&self, key: &K) -> Option<V>
\return the value for a key if it exists in the current scope, or
None if none.
pub fn activate_scope(&self, new_scope_ptr: &ScopePtr<K, V>)
Sourcepub fn flatten(&self) -> HashMap<K, V>
pub fn flatten(&self) -> HashMap<K, V>
Gets all values currently in scope. Port of the UNIT_TEST-only
test_flatten; kept pub (not test-gated) since the resolver’s own
tests use it too.
Sourcepub fn keys_by_scope(&self) -> Vec<Vec<K>>
pub fn keys_by_scope(&self) -> Vec<Vec<K>>
Gets keys in each scope. This may correspond to a ScopeChain.
Shadowed keys are ignored. Index 0 is innermost. Port of the
UNIT_TEST-only test_getKeysByScope; kept pub for the same
reason as flatten.