pub struct Env { /* private fields */ }Expand description
Lexical scope environment using a stack of frames.
Each frame is a Vec of bindings, scanned linearly. For typical scope sizes (<20 variables), linear scan with Symbol (u32) comparison is faster than HashMap due to cache locality.
Implementations§
Source§impl Env
impl Env
pub fn new() -> Self
Sourcepub fn pool(&self) -> &StringPool
pub fn pool(&self) -> &StringPool
Get a reference to the string pool.
Sourcepub fn pool_mut(&mut self) -> &mut StringPool
pub fn pool_mut(&mut self) -> &mut StringPool
Get a mutable reference to the string pool.
Sourcepub fn push_scope(&mut self)
pub fn push_scope(&mut self)
Push a new scope frame.
Sourcepub fn define(&mut self, name: String, value: Value, mutable: bool)
pub fn define(&mut self, name: String, value: Value, mutable: bool)
Define a new variable in the current scope.
Sourcepub fn define_sym(&mut self, sym: Symbol, value: Value, mutable: bool)
pub fn define_sym(&mut self, sym: Symbol, value: Value, mutable: bool)
Define a variable by symbol in the current scope.
Sourcepub fn get(&self, name: &str) -> Option<&Value>
pub fn get(&self, name: &str) -> Option<&Value>
Get a variable’s value by name, searching from innermost scope outward.
Sourcepub fn set(&mut self, name: &str, value: Value) -> Result<(), String>
pub fn set(&mut self, name: &str, value: Value) -> Result<(), String>
Set an existing variable’s value. Returns error if not found or not mutable.
Sourcepub fn set_sym(&mut self, sym: Symbol, value: Value) -> Result<(), String>
pub fn set_sym(&mut self, sym: Symbol, value: Value) -> Result<(), String>
Set a variable by symbol.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Env
impl !RefUnwindSafe for Env
impl Send for Env
impl Sync for Env
impl Unpin for Env
impl UnsafeUnpin for Env
impl !UnwindSafe for Env
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
Mutably borrows from an owned value. Read more