pub struct ShellEnv {
pub scopes: Vec<IndexMap<SmolStr, ShellVar>>,
}Expand description
The shell environment: a stack of variable scopes.
Fields§
§scopes: Vec<IndexMap<SmolStr, ShellVar>>Implementations§
Source§impl ShellEnv
impl ShellEnv
pub fn new() -> Self
Sourcepub fn get(&self, name: &str) -> Option<&ShellVar>
pub fn get(&self, name: &str) -> Option<&ShellVar>
Look up a variable by name, searching from innermost scope outward.
Sourcepub fn get_mut(&mut self, name: &str) -> Option<&mut ShellVar>
pub fn get_mut(&mut self, name: &str) -> Option<&mut ShellVar>
Get a mutable reference to a variable by name.
Sourcepub fn set(&mut self, name: SmolStr, var: ShellVar)
pub fn set(&mut self, name: SmolStr, var: ShellVar)
Set a variable in the current (innermost) scope.
Sourcepub fn push_scope(&mut self)
pub fn push_scope(&mut self)
Push a new scope (e.g. for a function call).
Sourcepub fn pop_scope(&mut self) -> Option<IndexMap<SmolStr, ShellVar>>
pub fn pop_scope(&mut self) -> Option<IndexMap<SmolStr, ShellVar>>
Pop the innermost scope. Returns None if only the global scope remains.
Sourcepub fn remove(&mut self, name: &str) -> Option<ShellVar>
pub fn remove(&mut self, name: &str) -> Option<ShellVar>
Remove a variable from the current (innermost) scope.
Sourcepub fn exported_vars(&self) -> IndexMap<SmolStr, SmolStr>
pub fn exported_vars(&self) -> IndexMap<SmolStr, SmolStr>
Iterate over all exported variables across all scopes (innermost wins for shadowed names).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ShellEnv
impl RefUnwindSafe for ShellEnv
impl Send for ShellEnv
impl Sync for ShellEnv
impl Unpin for ShellEnv
impl UnsafeUnpin for ShellEnv
impl UnwindSafe for ShellEnv
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