This crate contains two data structures for representing variable scopes:
ScopeSet. They are analogous to
but the main difference is that they store their data in multiple "layers",
When created, the
ScopeSet start with one base layer, which cannot be removed.
Additional layers can be added with
push_layer(), and removed with
Removing a layer removes the entries defined on it.
ScopeMap is ideal for representing variable scopes and associated values,
ScopeSet is more suitable for simply representing the presence of variables and their scopes.
use quickscope::*; let mut vars = ScopeMap::new(); // Define two variables in main scope vars.define("a", 1); vars.define("b", 2); // Add a child scope vars.push_layer(); // Override value of `a` vars.define("a", 3); assert_eq!(Some(&3), vars.get("a")); assert_eq!(Some(&2), vars.get("b")); // Remove child scope vars.pop_layer(); // Value of `a` is no longer overridden assert_eq!(Some(&1), vars.get("a"));
A layered hash map for representing scoped variables and their values.
A layered hash set for representing the scopes of variables.