pub struct Env { /* private fields */ }Expand description
An environment structure.
The environment is used by an interpreter and built-in functions and contains modules, variables, and a stack which are available by methods of the environment. Each stack element has a function module and local variables. Also, the environment has a script directory, a domain, the standard I/O enumerations, and a shared environment. The standard I/O enumerations determine which streams are used to the standard I/O in built-in functions.
Implementations§
Source§impl Env
impl Env
Creates an environment with the path to script directory, the domain, and the shared environment.
Also, this method takes the root module that has the variables and other modules.
Sourcepub fn clone_without_stack(&self) -> Self
pub fn clone_without_stack(&self) -> Self
Clones the environment without the stack.
Sourcepub fn mod_idents(&self) -> &[String]
pub fn mod_idents(&self) -> &[String]
Returns the identifiers of current module.
Sourcepub fn stack(
&self,
) -> &[(Arc<RwLock<ModNode<Value, ()>>>, BTreeMap<String, Value>)]
pub fn stack( &self, ) -> &[(Arc<RwLock<ModNode<Value, ()>>>, BTreeMap<String, Value>)]
Returns the stack.
Sourcepub fn script_dir(&self) -> &Path
pub fn script_dir(&self) -> &Path
Returns the path to script directory.
Sourcepub fn set_stdout(&mut self, output: Output)
pub fn set_stdout(&mut self, output: Output)
Sets the standard output enumeration.
Sourcepub fn set_stderr(&mut self, output: Output)
pub fn set_stderr(&mut self, output: Output)
Sets the standard error enumeration.
Retunrs the shared environment.
Sourcepub fn add_and_push_mod(&mut self, ident: String) -> Result<bool>
pub fn add_and_push_mod(&mut self, ident: String) -> Result<bool>
Adds an empty module to the current module and then the empty module is set as the current module.
This method adds the empty, sets the empty module as current, and returns true if a
module with the identifier doesn’t exist in the current module; otherwise this method
returns false.
Sourcepub fn pop_mod(&mut self) -> Result<bool>
pub fn pop_mod(&mut self) -> Result<bool>
Sets the parent module of the current module is set as the current module.
This method sets the parent module as current and returns true if the current module has
the parent module, otherwise this method returns false.
Sourcepub fn add_fun(&self, ident: String, fun: Arc<Fun>) -> Result<bool>
pub fn add_fun(&self, ident: String, fun: Arc<Fun>) -> Result<bool>
Adds the function.
This method adds the function and returns true if a function or a variable with the
identifier doesn’t exist in the current module, otherwise this method returnsfalse.
Sourcepub fn push_fun_mod_and_local_vars(
&mut self,
fun_mod_idents: &[String],
args: &[Arg],
arg_values: &[Value],
) -> Result<bool>
pub fn push_fun_mod_and_local_vars( &mut self, fun_mod_idents: &[String], args: &[Arg], arg_values: &[Value], ) -> Result<bool>
Pushes the function module and a local variables to the stack for applies the function.
This method pushes the function module and the local variables and returns true if all
identifiers of arguments are different, otherwise this method returns false.
Sourcepub fn pop_fun_mod_and_local_vars(&mut self)
pub fn pop_fun_mod_and_local_vars(&mut self)
Removes the last functoin module and the last local varables from stack.
Sourcepub fn var(&self, name: &Name) -> Result<Option<Value>>
pub fn var(&self, name: &Name) -> Result<Option<Value>>
Returns the variable value for the variable name if the variable exists, otherwise None.
Sourcepub fn set_var(&mut self, name: &Name, value: Value) -> Result<bool>
pub fn set_var(&mut self, name: &Name, value: Value) -> Result<bool>
Sets the variable value for the variable name and returns true if the variable can be
set, otherwise this method returns false.
Sourcepub fn remove_local_var(&mut self, ident: &String) -> bool
pub fn remove_local_var(&mut self, ident: &String) -> bool
Removes the local variable with the identifier and returns true if the stack isn’t
empty, otherwise this method returns false.
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.