quickscope/
lib.rs

1//! This crate contains two data structures for representing variable scopes:
2//! [`ScopeMap`] and [`ScopeSet`]. They are analogous to `HashMap` and `HashSet`,
3//! but the main difference is that they store their data in multiple "layers",
4//! or scopes. 
5//!
6//! When created, the [`ScopeMap`] and [`ScopeSet`] start with one base layer, which cannot be removed.
7//! Additional layers can be added with `push_layer()`, and removed with `pop_layer()`.
8//! Removing a layer removes the entries defined on it.
9//! 
10//! `ScopeMap` is ideal for representing variable scopes and associated values,
11//! while `ScopeSet` is more suitable for simply representing the presence of variables and their scopes.
12//! 
13//! ### Example
14//!
15//! ```rust
16//! use quickscope::*;
17//!
18//! let mut vars = ScopeMap::new();
19//! 
20//! // Define two variables in main scope
21//! vars.define("a", 1);
22//! vars.define("b", 2);
23//! 
24//! // Add a child scope
25//! vars.push_layer();
26//! 
27//! // Override value of `a`
28//! vars.define("a", 3);
29//! 
30//! assert_eq!(Some(&3), vars.get("a"));
31//! assert_eq!(Some(&2), vars.get("b"));
32//! 
33//! // Remove child scope
34//! vars.pop_layer();
35//! 
36//! // Value of `a` is no longer overridden
37//! assert_eq!(Some(&1), vars.get("a"));
38//! ```
39//! 
40//! [`ScopeMap`]: map/struct.ScopeMap.html
41//! [`ScopeSet`]: set/struct.ScopeSet.html
42
43mod map;
44mod set;
45
46pub use map::*;
47pub use set::*;
48